• iOS 8中CLLocationManager及MKMapView showUserLocation失败的解决的方法


              用XCode 6编译的原来XCode 5.1.1写的程序时,发现原来写的CLLocationManager定位的代码以及MKmapView的showUserLocation失效。查了一下,XCode 6选用iOS 8 SDK编译app的话,须要调用CLLocationManage 的requestAlwaysAuthorization 方法。

    操作过程例如以下:

    1. 在AppDelegate的didFinishLaunchingWithOptions:方法中 [self.window makeKeyAndVisible]; 之后加入下面代码

        CLLocationManager *locationManager = [[CLLocationManager alloc] init];
        // 判斷是否 iOS 8
        if([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
            [locationManager requestAlwaysAuthorization]; // 永久授权
            [locationManager requestWhenInUseAuthorization]; //使用中授权
        }
        [locationManager startUpdatingLocation];

    2. 在 info.plist里增加:
    NSLocationWhenInUseDescription,同意在前台获取GPS的描写叙述
    NSLocationAlwaysUsageDescription,同意在后台获取GPS的描写叙述


          完毕。


    參考:

    http://www.cnblogs.com/tx8899/p/3989087.html

    http://blog.uniba.jp/post/91830563468/ios-8

    http://www.cocoachina.com/bbs/read.php?tid-217107.html

    http://www.cocoachina.com/ask/questions/show/87714

    http://9to5mac.com/2014/06/04/apple-improves-location-services-in-ios-8-with-when-in-use-mode-visit-monitoring/

    http://derjohng.doitwell.tw/6197/%E9%9B%BB%E8%85%A6%E9%A1%9E%E5%88%A5/%E8%BB%9F%E9%AB%94%E7%AD%86%E8%A8%98/ios8-%E4%B8%8B%E5%AE%9A%E4%BD%8D-cllocationmanager-%E7%9A%84%E6%94%B9%E8%AE%8A/

    http://www.cocoachina.com/ask/questions/show/113705/CLLocationManager%E8%8E%B7%E5%8F%96%E5%9C%B0%E5%9D%80%E5%81%8F%E5%B7%AE



  • 相关阅读:
    量化生产力Quantifying Productivity
    计算机视觉和人工智能的状态:我们已经走得很远了 The state of Computer Vision and AI: we are really, really far away.
    量化Hacker News 中50天的数据 Quantifying Hacker News with 50 days of data
    神经网络指南Hacker's guide to Neural Networks
    PHP Error 和 Logging 函数
    PHP 5 Directory 函数
    PHP 5 Date/Time 函数
    PHP cURL 函数
    PHP 5 Calendar 函数
    PHP 5 Array 函数
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/4170207.html
Copyright © 2020-2023  润新知