• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

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

[复制链接]
菜鸟教程小白 发表于 2022-12-11 22:40:53 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我正在制作一个应用程序,它将记录用户在 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")
        }



Best Answer-推荐答案


找到 THIS线程,并且有一个答案说:

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.

所以对于 authorization 我尝试了 startActivityUpdates 如下所示

self.activityManager.startActivityUpdates(to: OperationQueue.main, withHandler: {(data: CMMotionActivity!) -> Void in

})

你需要声明 let activityManager = CMMotionActivityManager()

一旦用户允许 如果 CMSensorRecorder.authorizationStatus() == .authorized { 将是 true

关于ios - CMSensorRecorder 未获得授权,但从未提示我授权?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55566272/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap