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]; 
 
 
 
 
 
 
posted @ 2014-11-29 23:46  Colaless  阅读(575)  评论(0编辑  收藏  举报