首页 > 解决方案 > iOS 11.4 not asking Privacy Usage ( Privacy - Motion Usage Description has been set )

问题描述

I'm stumped, iOS 11.4 ( 15F79 ), iPhone 6. Cannot get the App to Ask for Motion Data. info.plist has been set via the editor and double checked via the info.plist open in textWrangler, Also deleted key and saved via textWrangler.

 <key>NSMotionUsageDescription</key>
 <string>This app needs your Phones motion manager to update when the phone is tilted. Please allow this App to use your phones tilt devices</string>

I have deleted then reinstalled the app about 10 times. I have restared the phone 5 times. I have checked through settings and my app does NOT show up in Privacy-Motion and Fitness or anywhere else in settings. I am using a free developer account, maybe that has something to do with it?

I created a new Xcode game template and changed nothing apart from importing CoreMotion and this code

**** Edited, sorry I forgot to say I had started the instance, just forgot to put it here, just in case someone thinks that's the problem ************

let motionManager = CMMotionManager()

override func didMove(to view: SKView) {

 motionManager.startDeviceMotionUpdates()

    if motionManager.isDeviceMotionActive == true {
        motionManager.accelerometerUpdateInterval = 0.2
        motionManager.startAccelerometerUpdates(to:  OperationQueue.current!, withHandler: {
        (accelerometerData: CMAccelerometerData!, error: NSError!) in
            let acceleration = accelerometerData.acceleration
            print(accelerometerData)
        } as! CMAccelerometerHandler)
    }else{
        print(CMMotionActivityManager.authorizationStatus().rawValue)
    }

which prints a 0 ( an Enum - case not determined ) to the console.

In my actual app it was a 3 ( same Enum - case Denied ).

As I've said, I have uninstalled, reinstalled, edited plist via Xcode and text wrangler ( a code editor ) , tried different versions of the code above, tried the code in different places ( in did move to view, in class )tried code off apple docs. etc.... I haven't been asked the NSUsage question and the App keeps crashing.

I have looked for ways to get the Alert fired up, As in CLLocationManager.requestWhenInUseAuthorization() but I cannot find a comparable CMMotion version ( I don't think there is one. ) I have created a new swift file , imported Foundation and CMMotion and just put that code there, But still no Alert asking for Motion Data.

I tried a single view app template instead of a game template thinking that might be the issue, Nope.

What do I do?

Any help Appreciated. Thanks

标签: iosswiftxcode

解决方案


您混淆了两个相关但不同的类。

CMMotionManager可以访问加速度计、磁力计和陀螺仪数据。它不需要任何用户许可,因为此信息不被视为与隐私相关。

在您的else条款中,您正在检查CMMotionActivityManager. 此对象报告设备运动类型(步行、跑步、驾驶)。此信息被认为与隐私相关,当您创建此类的实例并从中请求数据时,将显示权限警报。

else被触发的原因是因为你正在检查isDeviceMotionActive;这将false一直持续到你打电话startDeviceMotionUpdates,你永远不会这样做。即使您使用过isAccelerometerActive,也会遇到问题,因为您调用startAccelerometerUpdatesif永远无法到达的子句。

您可能打算检查isAccelerometerAvailable. 如果返回false,那么您无能为力;该设备没有加速度计。

更新

isDeviceMotionActive调用后立即检查是没有意义的startDeviceMotion

  1. 你知道它是活跃的;你刚开始
  2. 我想启动需要一些时间,所以false如果你立即检查,你可以期望得到。

Apple 建议您不要为每种运动设备类型配备一个以上的观察员,因此检查的目的是is...Active确保您不会start...再次调用(如果您已经这样做了)。

如果您只想要陀螺仪数据,那么您根本不需要调用startDeviceMotionUpdates


推荐阅读