gpt4 book ai didi

ios - CMSensorRecorder 未获得授权,但系统从未提示我授予授权?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:59:11 28 4
gpt4 key购买 nike

我正在制作一个应用程序,可以在 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() returns true only after your app is authorized in Privacy/Motion & Fitness (on the iPhone). Then to make the app authorized for Motion & Fitenss I had to access one of the core motion function (like startActivityUpdatesToQueue or even recordAccelerometerForDuration). After that you just need to confirm on the iPhone and from now on CMSensorRecorder.isAuthorizedForRecording() returns true.

Still, I can't get any data from the CMSensorRecroding. In my case the accelerometerDataFromDate function 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:

  1. I am starting the recoding session with recordAccelerometerForDuration(30). Here I record the current date: recordingStartDate = NSDate().

  2. 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.

  3. 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com