if (OSVersion>=8.0) { CLLocationManager *clloc = [[CLLocationManager alloc] init]; [clloc requestAlwaysAuthorization]; }
除了以上的代码,还须要在app的plist文件里面添加两个属性NSLocationAlwaysUsageDescription,NSLocationWhenInUseDescription。这两个属性的value你能够自定义也能够不填。ios
if(OSVersion>=8.0){//8.0之后使用这种方法来注册推送通知 UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert categories:nil]; [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound; [[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes]; }else{ [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge)]; }