Location Services not working in iOS 8

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

    I was working on an app that was upgraded to iOS 8 and location services stopped working. You'll probably get and error in the Debug area like so:

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

    I did the least intrusive procedure. First add NSLocationAlwaysUsageDescription entry to your info.plist:

    Enter image description here

    Notice I didn't fill out the value for this key. This still works, and I'm not concerned because this is a in house app. Also, there is already a title asking to use location services, so I didn't want to do anything redundant.

    Next I created a conditional for iOS 8:

    if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
        [_locationManager requestAlwaysAuthorization];
    }
    

    After this the locationManager:didChangeAuthorizationStatus: method is call:

    - (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:  (CLAuthorizationStatus)status
    {
        [self gotoCurrenLocation];
    }
    

    And now everything works fine. As always, check out the documentation.

提交回复
热议问题