Location Services not working in iOS 8

前端 未结 26 1959
滥情空心
滥情空心 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:40

    To ensure that this is backwards compatible with iOS 7, you should check whether the user is running iOS 8 or iOS 7. For example:

    #define IS_OS_8_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
    
    //In ViewDidLoad
    if(IS_OS_8_OR_LATER) {
       [self.locationManager requestAlwaysAuthorization];
    }
    
    [self.locationManager startUpdatingLocation];
    
    0 讨论(0)
  • 2020-11-21 10:40

    One common error for Swift developers:

    First make sure you add a value to the plist for either NSLocationWhenInUseUsageDescription or NSLocationAlwaysUsageDescription.

    If you are still not seeing a window pop up asking for authorization, look to see if you are putting the line var locationManager = CLLocationManager() in your View Controller's viewDidLoad method. If you do, then even if you call locationManager.requestWhenInUseAuthorization(), nothing will show up. This is because after viewDidLoad executes, the locationManager variable is deallocated (cleared out).

    The solution is to locate the line var locationManager = CLLocationManager() at the top of the class method.

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

    Before [locationManager startUpdatingLocation];, add an iOS8 location services request:

    if([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)])
        [locationManager requestAlwaysAuthorization];
    

    Edit your app's Info.plist and add key NSLocationAlwaysUsageDescription with the string value that will be displayed to the user (for example, We do our best to preserve your battery life.)

    If your app needs location services only while the app is open, replace:

    requestAlwaysAuthorization with requestWhenInUseAuthorization and

    NSLocationAlwaysUsageDescription with NSLocationWhenInUseUsageDescription.

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

    To Access User Location in iOS 8 you will have to add,

    NSLocationAlwaysUsageDescription in the Info.plist 
    

    This will ask the user for the permission to get their current location.

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

    Keep Cocoa Keys information always at your fingertips for those updates, here is the link:

    https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW26

    Enjoy.

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

    In order to access the users location in iOS. You need to add two keys

    NSLocationWhenInUseUsageDescription

    NSLocationAlwaysUsageDescription

    into the Info.plist file.

        <key>NSLocationWhenInUseUsageDescription</key>
        <string>Because I want to know where you are!</string>
        <key>NSLocationAlwaysUsageDescription</key>
        <string>Want to know where you are!</string>
    

    See this below image.

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