Location Services not working in iOS 8

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

    1. Add key NSLocationWhenInUseUsageDescription or NSLocationAlwaysUsageDescription (background GPS use) with string asking to use GPS on each info.plist from each target.

    2. Ask for permission by running:

      [self initLocationManager:locationManager];

    Where initLocationManager is:

    // asks for GPS authorization on iOS 8
    -(void) initLocationManager:(CLLocationManager *) locationManager{
    
        locationManager = [[CLLocationManager alloc]init];
    
        if([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)])
            [locationManager requestAlwaysAuthorization];
    }
    

    Remember that if the keys are not on each info.plist for each target the app will not ask the user. The if provides compatibility with iOS 7 and the respondsToSelector: method guarantees future compatibility rather than just solving the issue for iOS 7 and 8.

提交回复
热议问题