1
我的應用程序中的位置服務在第一次運行時不起作用。第二次,然後任何時候,它都可以正常工作。這裏是我的代碼:didUpdateLocation不是第一次運行
- (void)viewDidLoad {
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.allowsBackgroundLocationUpdates = true;
[locationManager requestAlwaysAuthorization];
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedAlways ||
[CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse) {
[locationManager startUpdatingLocation];
}
}
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations
{
latitude = locationManager.location.coordinate.latitude;
longitude = locationManager.location.coordinate.longitude;
NSLog(@"New Location. Lat: %f, Long: %f", latitude, longitude);
}