iOS 8 Mapview Current Location not fire

后端 未结 3 1987
你的背包
你的背包 2021-01-05 18:45

MKMapview current user location not fire in iOS-8,previous iOS-7 & iOS-6 are working fine.

     self.         


        
3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-05 19:17

    In iOS8, you need to request user's authorization before getting their location.

    There are two kinds of request:

    -[CLLocationManager requestWhenInUseAuthorization] lets you get users' location only when the app is awaken.

    -[CLLocationManager requestAlwaysAuthorization] lets you get users' location even when it's in the background.

    You can choose between them accordingly.

    For example, put this before you start updating location:

    // ask for authorization
    CLLocationManager * locationManager = [[CLLocationManager alloc] init];
    // check before requesting, otherwise it might crash in older version
    if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { 
    
         [locationManager requestWhenInUseAuthorization];
    
    }
    

    Furthermore, don't forget to add two keys

    NSLocationWhenInUseUsageDescription
    

    and

    NSLocationAlwaysUsageDescription
    

    into your info.plist.

    Leave the values empty to use the default messages or you can customize your own by inputting the values.

提交回复
热议问题