iOS8以后定位功能的更改

 在iOS8以后,在使用以前的定位方法的话,程序接收不到应用调用系统服务的提示,须要作一下更改。
在iOS8中,定位的使用有两种,一种是在使用该应用的时候访问用户的位置信息,须要在另一种是容许在并未使用应用程序的时候访问用户的位置信息。
代码以下:
    self.locationManager = [[CLLocationManager alloc] init];
    if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
        [self.locationManager requestAlwaysAuthorization];
        // 须要在plist文件中添加默认缺省的字段“NSLocationAlwaysUsageDescription”,这个提示是:“容许应用程序在您并未使用该应用程序时访问您的位置吗?”NSLocationAlwaysUsageDescription对应的值是告诉用户使用定位的目的或者是标记。
        [self.locationManager requestWhenInUseAuthorization];
// 须要在plist文件中添加默认缺省的字段“NSLocationWhenInUseDescription”,这个时候的提示是:“容许应用程序在您使用该应用程序时访问您的位置吗?”
    }
    self.locationManager.delegate = self;
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    self.locationManager.distanceFilter = 1000.0f;
    [self.locationManager startUpdatingLocation];
本地通知:在iOS8以后,以前使用的本地通知的方法,用户再也不能收到系统提示了,须要在建立本地通知的时候进行注册,代码以下:
// 初始化一个本地通知
    UILocalNotification *localNotification = [[UILocalNotification alloc] init];
 // 设置本地通知的时间
    NSDate *fireDate = [NSDate dateWithTimeIntervalSinceNow:10];
 
/*下面的几行代码是须要添加的
UIUserNotificationSettings *settings = [UIUserNotificationSettings  settingsForTypes:UIUserNotificationTypeBadge |  UIUserNotificationTypeSound | UIUserNotificationTypeAlert  categories:nil];
     [[UIApplication sharedApplication]         
                registerUserNotificationSettings:settings];
*/
// 注册通知
    [application scheduleLocalNotification:localNotification]; 
 
 
 
 
 
 
相关文章
相关标签/搜索