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]; 
     
     
     
     
     
     
  • 相关阅读:
    会话追踪技术
    request session application
    Java CAS同步机制 原理详解(为什么并发环境下的COUNT自增操作不安全): Atomic原子类底层用的不是传统意义的锁机制,而是无锁化的CAS机制,通过CAS机制保证多线程修改一个数值的安全性。
    mysql连接拍错总结
    git 从分支上创建一个分支
    linux ---> taskkill pid 8080 /f
    阿里java开发规范 强制约束
    for break
    Mybatis Update操作返回值问题
    springboot 缓存架构
  • 原文地址:https://www.cnblogs.com/zhangshan/p/4132257.html
Copyright © 2011-2022 走看看