如果用户禁用了设备位置服务,我需要在我的应用程序中定位用户我正在检查这个。
if([CLLocationManager locationServicesEnabled])
{
if([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])
{
[locationManager requestWhenInUseAuthorization];
}
}
else if(![CLLocationManager locationServicesEnabled])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Location Services are disabled please enable location services to enjoy nearby experience" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Settings", nil];
alert.tag = 103;
[alert show];
}
在我的提醒视图中,我将用户定位到此类位置设置
else if(alertView.tag == 103)
{
if(buttonIndex == 1)
{
NSURL*url=[NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"];
[[UIApplication sharedApplication] openURL:url];
}
}
用户从设置中返回后如何再次获取位置
答案 0 :(得分:1)
使用Location Delegate
方法: -
if([CLLocationManager locationServicesEnabled])
{
if([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])
{
[locationManager requestWhenInUseAuthorization];
//Set Location Delegate
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
//Update Location start
[locationManager startUpdatingLocation];
}
}
else if(![CLLocationManager locationServicesEnabled])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Location Services are disabled please enable location services to enjoy nearby experience" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Settings", nil];
alert.tag = 103;
[alert show];
}
#pragma mark CLLocationManager Delegate
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
//NSLog(@"OldLocation %f %f", oldLocation.coordinate.latitude, oldLocation.coordinate.longitude);
//NSLog(@"NewLocation %f %f", newLocation.coordinate.latitude, newLocation.coordinate.longitude);
[locationManager stopUpdatingLocation];
}
答案 1 :(得分:1)
您可以在applicationWillEnterForeground
中管理自己的内容,因为当您设置app to your app
时会调用此方法。
您可以使用此方法编写代码,例如
if([CLLocationManager locationServicesEnabled])
{
if([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])
{
[locationManager requestWhenInUseAuthorization];
}
}