zoukankan      html  css  js  c++  java
  • 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]; 
     
     
     
     
     
     
  • 相关阅读:
    U盘修复
    在tomcat中配置jdk的不同版本
    集​群​t​o​m​c​a​t​+​a​p​a​c​h​e​配​置​文​档
    如何挂自己的web项目(免费拥有自己的网站及域名)
    JQuery对表格进行排序
    JQuery中对各种域进行隐藏和显示操作
    大文件批量上传断点续传文件秒传
    web 开发常用字符串表达式匹配
    spring 工具类大集合
    spring 是如何注入对象的和bean 创建过程分析
  • 原文地址:https://www.cnblogs.com/zhangshan/p/4132257.html
Copyright © 2011-2022 走看看