iOS Swift4 Didn't Ask for Permission on App

1k Views Asked by At

I need access to CMAltimeter in my App. So of course I need to ask for permission. And I add the Privacy - Location When In Use Usage Description and of course Privacy - Motion Usage Description with an Value in info.plist but the App never asks for Permission and the Authorization Status is always not determined

(Device -> iPhone XR iOS12) and newest Xcode. My Signing in Xcode is only Personal Team with my Apple ID because we only need this for the university. (And till this day I haven't buy the Developer License) The App and CoreMotion runs. (CMDeviceMotion doesn't need permissions)

func myDeviceMotionQFE(){
    if CMAltimeter.isRelativeAltitudeAvailable() {
        switch CMAltimeter.authorizationStatus() {
        case .notDetermined:
            print("Altimeter -> NotDetermined")
            break
        case .denied:
            print("Altimeter -> Denied")
            break
        case .restricted:
            print("Altimeter -> Restricted")
            break
        case .authorized:
            print("Altimeter -> Authorized")
}
2

There are 2 best solutions below

0
On BEST ANSWER

My initial problem was that startRelativeAltitudeUpdates(to:withHandler) did not work and was sidetracked by exactly the same problem: CMAltimeter.authorizationStatus() was always .notDetermined.

However it turned out that that CMAltimeter instance got out of scope and was automatically ARC'ed and the handler not called any more.

Summary: There is no requestAuthorization() for CMAltimeter in IOS12, neither one is needed.

1
On

Welcome! You need to do two things to get permission for altimetry data. First is the plist description that you already have. The second is to call CMAltimeter.authorizationStatus(). This will ask the user for permission using the string you have in the plist.

You can get one of four results as in CMAltimeter CMAuthorizationStatus: notDetermined, restricted, denied, or authorized. If you get authorized, you're good to go. If you get denied the user hasn't given their permission. Restricted is that there's some system-wide restriction on this location data (might be from MDM perhaps).

Search in your Xcode documentation for CMAltimeter, authorizationStatus, and CMAuthorizationStatus.

When you get "authorized" response, you can call startRelativeAltitudeUdpates with a handler and your app will get the updates when data is available.