获取经纬度:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a
self.mgr.delegate = self;
self.mgr.distanceFilter = 1000;
self.mgr.desiredAccuracy = kCLLocationAccuracyKilometer;
//在ios8中不仅仅要主动请求授权,还需要在info.plist文件中配置属性弹出授权界面
if ([[[UIDevice currentDevice] systemVersion] doubleValue] > 8.0) {
// 主动要求用户授权,授权状态改变就会通知代理
[self.mgr requestAlwaysAuthorization];// 前台+后台
// [self.mgr requestWhenInUseAuthorization];//前台
} else {
[self.mgr startUpdatingLocation];
}
}
// 授权成功后调用此方法
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
if (status == kCLAuthorizationStatusNotDetermined) {
NSLog(@"等待授权");
} else if (status == kCLAuthorizationStatusRestricted || status == kCLAuthorizationStatusDenied) {
NSLog(@"授权失败");
} else {
NSLog(@"授权成功");
[self.mgr startUpdatingLocation];
}
}
- (BOOL)prefersStatusBarHidden {
return YES;
}
推送通知:
- (CLLocationManager *)mgr {
if (!_mgr) {
_mgr = [[CLLocationManager alloc] init];
}
return _mgr;
}
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
NSLog(@"%s", __func__);
CLLocation *location = [locations lastObject];
NSLog(@"%f %f", location.coordinate.longitude, location.coordinate.latitude);
[self.mgr stopUpdatingLocation];
}
跳转到系统的设置界面:
http://www.jianshu.com/p/e4d34c03bb05
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1) {
if ([[UIDevice currentDevice].systemVersion doubleValue] > 7.0) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
} else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=Privacy"]];
}
}
// [self dismissViewControllerAnimated:YES completion:nil];
}