Location Services not working in iOS 8

前端 未结 26 1957
滥情空心
滥情空心 2020-11-21 10:23

My app that worked fine on iOS 7 doesn\'t work with the iOS 8 SDK.

CLLocationManager doesn\'t return a location, and I don\'t see my app under

相关标签:
26条回答
  • 2020-11-21 10:52

    I was pulling my hair out with the same problem. Xcode gives you the error:

    Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.

    But even if you implement one of the above methods, it won't prompt the user unless there is an entry in the info.plist for NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription.

    Add the following lines to your info.plist where the string values represent the reason you you need to access the users location

    <key>NSLocationWhenInUseUsageDescription</key>
    <string>This application requires location services to work</string>
    
    <key>NSLocationAlwaysUsageDescription</key>
    <string>This application requires location services to work</string>
    

    I think these entries may have been missing since I started this project in Xcode 5. I'm guessing Xcode 6 might add default entries for these keys but have not confirmed.

    You can find more information on these two Settings here

    0 讨论(0)
  • 2020-11-21 10:53

    According to the Apple docs:

    • https://developer.apple.com/documentation/corelocation/requesting_permission_to_use_location_services
    • https://developer.apple.com/documentation/corelocation/cllocationmanager/1620562-requestwheninuseauthorization

    As of iOS 8, the presence of a NSLocationWhenInUseUsageDescription or a NSLocationAlwaysUsageDescription key value in your app's Info.plist file is required. It's then also necessary to request permission from the user prior to registering for location updates, either by calling [self.myLocationManager requestWhenInUseAuthorization] or [self.myLocationManager requestAlwaysAuthorization] depending on your need. The string you entered into the Info.plist will then be displayed in the ensuing dialog.

    If the user grants permission, it's business as usual. If they deny permission, then the delegate is not informed of location updates.

    0 讨论(0)
提交回复
热议问题