Search code examples
swiftswift2authorizationcore-motionhealthkit

CoreMotion authorization problems


I am currently developing an app that will use a combination of three libraries: CoreLocation, CoreMotion and Healthkit.

My issue is that when I initialize CoreLocation and Healthkit, I get the the dialog to allow authorization. However, with CoreMotion, I don't get any dialog asking for authorization, just an error "CMErrorDomain=105" (ie. access denied). Privacy settings for "Motion & Fitness" do not show any entry for the app. Nor does the privacy settings for the app show any entry related to Motion. I have wiped my testing device several times to eliminate any pre-existing setting.

App built for ios 9.2 using Swift 2.1. Tested on 5S and 6S+, with identical results (no authorization dialog)

Here is the code used to test whether pedometer is available and whether we can gather data (ie. allowed). "pedometer" is declared at class scope. This function is (currently) attached to a button that is user triggered.

func checkCM() {
        pedometer.queryPedometerDataFromDate(NSDate(), toDate: NSDate()) {
            (data, error) -> Void in
            if error != nil {
               //error handler
               print(error?.description)

            } else {
                // no errors!
            }
        }

}

The confusing part is that this function has also been tested on another bare-bones app, and works correctly (ie. the dialog to allow "Motion & Fitness" is displayed), on the same devices. All relevant system settings are configured as expected, and other pedometer\cm apps will work.

So the issues is that something about my app is preventing the CoreMotion authorization dialog to be displayed. Are there any known "gotchas" or issues related to working with CoreMotion and authorization?


Solution

  • I had that issue during a week. Even during the first launch of the app the dialog was not showing up... With that error 105. For me it was due to my info.plist that as somehow delete my app bundle name... So make sure you have the correct name in that one ;)