我正在制作一个应用程序,可以在 Apple Watch 上记录一段时间内的用户加速度,并将该数据发送到配对的 iPhone。我正在使用 CoreMotion 框架来实现这一目标。
我的问题:我一直在使用 CMSensorRecorder 对象来记录数据。这工作了一段时间,但 CMSensorRecorder.authorizationStatus() 现在“未授权”。
从一开始,我在 watch 和手机应用程序的 info.plist 文件中都有一个 NSMotionUsageDescription。我已经删除并重新添加了这些,但没有运气。
我记得应用程序显示允许运动跟踪的提示,但无法重新创建显示提示的功能。非常感谢有关如何再次启用 CMSensorRecorder 的任何建议。干杯。
我的代码初始化CMSensorRecorder:
if CMSensorRecorder.isAccelerometerRecordingAvailable(){
if CMSensorRecorder.authorizationStatus() == .authorized {
print("\(Date()): recorder started")
DispatchQueue.global(qos: .background).async {
DispatchQueue.global(qos: .background).sync{
self.dateStart = Date()
self.recorder.recordAccelerometer(forDuration: self.duration)
}
}
}
else {
print("\(CMSensorRecorder.authorizationStatus())")
self.xAccLabel.setText("not authorised")
}
}
else {
print ("Recording not available")
self.xAccLabel.setText("Not available")
}
最佳答案
找到 THIS thread for that that is one answer for that that says:
I found that the
CMSensorRecorder.isAuthorizedForRecording()returnstrueonly after your app is authorized inPrivacy/Motion&Fitness(on the iPhone). Then to make the app authorized forMotion&FitenssI had to access one of the core motion function (likestartActivityUpdatesToQueueor evenrecordAccelerometerForDuration). After that you just need to confirm on the iPhone and from now onCMSensorRecorder.isAuthorizedForRecording()returnstrue.Still, I can't get any data from the
CMSensorRecroding. In my case theaccelerometerDataFromDatefunction does not return any data - the returned value is always nil. Because it is said elsewhere that it can take up to 3mins for the data to become available, I am doing the following scenario:
I am starting the recoding session with
recordAccelerometerForDuration(30). Here I record the current date:recordingStartDate = NSDate().I wait more than
3min30s(keeping the app on the watch active) and after this time I call:
accelerometerDataFromDate(NSDate(timeInterval: 10, sinceDate: recordingStartDate), toDate: NSDate(timeInterval: 20, sinceDate: recordingStartDate)As you can see, I making a 10s window within the requested 30s recording frame.
I get
nil.I also tried shorter timeouts, accessing the data immediately, and even activating the accelerometer before calling ecordAccelerometerForDuration. Nothing helps, I still get nil back from
accelerometerDataFromDate.I really wonder how you guys are able to get any readings back from the sensor recorder...
Maybe things will get better after September 9.
所以对于授权,我尝试了如下所示的startActivityUpdates
self.activityManager.startActivityUpdates(to: OperationQueue.main, withHandler: {(data: CMMotionActivity!) -> Void in
})
并且你需要声明let activityManager = CMMotionActivityManager()
一旦用户允许,if CMSensorRecorder.authorizationStatus() == .authorized { 将为 true。
关于ios - CMSensorRecorder 未获得授权,但系统从未提示我授予授权?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55566272/
我使用的是Firefox版本36.0.1和Selenium-Webdrivergem版本2.45.0。我能够创建Firefox实例,但无法使用脚本继续进行进一步的操作无法在60秒内获得稳定的Firefox连接(127.0.0.1:7055)错误。有人能帮帮我吗? 最佳答案 我遇到了同样的问题。降级到firefoxv33后一切正常。您可以找到旧版本here 关于ruby-无法在60秒内获得稳定的Firefox连接(127.0.0.1:7055),我们在StackOverflow上找到一个类
这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下
我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的
电脑0x0000001A蓝屏错误怎么U盘重装系统教学分享。有用户电脑开机之后遇到了系统蓝屏的情况。系统蓝屏问题很多时候都是系统bug,只有通过重装系统来进行解决。那么蓝屏问题如何通过U盘重装新系统来解决呢?来看看以下的详细操作方法教学吧。 准备工作: 1、U盘一个(尽量使用8G以上的U盘)。 2、一台正常联网可使用的电脑。 3、ghost或ISO系统镜像文件(Win10系统下载_Win10专业版_windows10正式版下载-系统之家)。 4、在本页面下载U盘启动盘制作工具:系统之家U盘启动工具。 U盘启动盘制作步骤: 注意:制作期间,U盘会被格式化,因此U盘中的重要文件请注
在应用开发中,有时候我们需要获取系统的设备信息,用于数据上报和行为分析。那在鸿蒙系统中,我们应该怎么去获取设备的系统信息呢,比如说获取手机的系统版本号、手机的制造商、手机型号等数据。1、获取方式这里分为两种情况,一种是设备信息的获取,一种是系统信息的获取。1.1、获取设备信息获取设备信息,鸿蒙的SDK包为我们提供了DeviceInfo类,通过该类的一些静态方法,可以获取设备信息,DeviceInfo类的包路径为:ohos.system.DeviceInfo.具体的方法如下:ModifierandTypeMethodDescriptionstatic StringgetAbiList()Obt
1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里
需求:要创建虚拟机,就需要给他提供一个虚拟的磁盘,我们就在/opt目录下创建一个10G大小的raw格式的虚拟磁盘CentOS-7-x86_64.raw命令格式:qemu-imgcreate-f磁盘格式磁盘名称磁盘大小qemu-imgcreate-f磁盘格式-o?1.创建磁盘qemu-imgcreate-fraw/opt/CentOS-7-x86_64.raw10G执行效果#ls/opt/CentOS-7-x86_64.raw2.安装虚拟机使用virt-install命令,基于我们提供的系统镜像和虚拟磁盘来创建一个虚拟机,另外在创建虚拟机之前,提前打开vnc客户端,在创建虚拟机的时候,通过vnc
我想在IRB中浏览文件系统并让提示更改以反射(reflect)当前工作目录,但我不知道如何在每个命令后进行提示更新。最终,我想在日常工作中更多地使用IRB,让bash溜走。我在我的.irbrc中试过这个:require'fileutils'includeFileUtilsIRB.conf[:PROMPT][:CUSTOM]={:PROMPT_N=>"\e[1m:\e[m",:PROMPT_I=>"\e[1m#{pwd}>\e[m",:PROMPT_S=>"FOO",:PROMPT_C=>"\e[1m#{pwd}>\e[m",:RETURN=>""}IRB.conf[:PROMPT_MO
因为我现在正在做一些时间测量,我想知道是否可以在不使用Benchmark类或命令行实用程序time的情况下测量用户时间或系统时间。使用Time类只显示挂钟时间,而不显示系统和用户时间,但是我正在寻找具有相同灵active的解决方案,例如time=TimeUtility.now#somecodeuser,system,real=TimeUtility.now-time原因是我有点不喜欢Benchmark,因为它不能只返回数字(编辑:我错了-它可以。请参阅下面的答案。)。当然,我可以解析输出,但感觉不对。*NIX系统的time实用程序也应该可以解决我的问题,但我想知道是否已经在Ruby中实
print"Enteryourpassword:"pass=STDIN.noecho(&:gets)puts"Yourpasswordis#{pass}!"输出:Enteryourpassword:input.rb:2:in`':undefinedmethod`noecho'for#>(NoMethodError) 最佳答案 一开始require'io/console'后来的Ruby1.9.3 关于ruby-为什么不能使用类IO的实例方法noecho?,我们在StackOverflow上