iOS 8 Mapview Current Location not fire

后端 未结 3 1986
你的背包
你的背包 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:10

    In ios 8 Authorization is required as below

        NSString * osVersion = [[UIDevice currentDevice] systemVersion];
        if ([osVersion floatValue]>= 8.0 ) {
        [_CLLocationManager requestAlwaysAuthorization]; //Requests permission to use location services whenever the app is running. 
    // [_CLLocationManager requestWhenInUseAuthorization]; //Requests permission to use location services while the app is in the foreground. 
        }
        [_CLLocationManager startUpdatingLocation];
    

    And you need to add two keys in the plist

    1.NSLocationAlwaysUsageDescription

    2.NSLocationWhenInUseUsageDescription

    enter image description here

    0 讨论(0)
  • 2021-01-05 19:10

    In iOS 8 Mapview Current Location fire using

    You can set in your .plist file

    <key>NSLocationWhenInUseUsageDescription</key>
    <string>Your app name Or Other string</string>
    <key>NSLocationAlwaysUsageDescription</key>
    <string>Your app name Or Other string</string>
    

    And your code side you just implement this

    CLLocationManager * locationmanager = [CLLocationManager new];

    locationmanager.delegate = self;
    locationmanager.distanceFilter = kCLDistanceFilterNone;
    locationmanager.desiredAccuracy = kCLLocationAccuracyBest;
    [locationmanager startUpdatingLocation];    
    [locationmanager requestAlwaysAuthorization];
    

    -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {

    location = [locations objectAtIndex:0];
    [locationmanager stopUpdatingLocation];
    

    }

    I am using this my app get perfect current location.

    0 讨论(0)
  • 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.

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