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