推送通知

获取经纬度:


- (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];
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值