zoukankan      html  css  js  c++  java
  • iOS定位权限与使用阐述 (含iOS14定位适配)

    https://blog.csdn.net/weixin_30419799/article/details/95878160

    https://www.jianshu.com/p/4541cd070423

    在 iOS 8 上编译会出现以下 log :

    Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first. 

    经搜索得到解决方法如下: 

    1、修改info.plist: 

        新增key值为NSLocationWhenInUseUsageDescription 或 NSLocationAlwaysUsageDescription(这里,我将两个都加了进去),一定要设置内容,不然不能调用授权。(个别就是info.plist中还需要包含Supported interface orientations 这个Array字段。然后运行就解决了)。

    2、修改代码:

        在调用方法startUpdatingLocation的前面加上一句

    1  if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
    2    [locationManager requestWhenInUseAuthorization];
    3  }
       

    ============================

    3、博客原文修改方法:

    1
    2
    3
    4
    5
    6
    7
    locationManager = [[CLLocationManager alloc] init];
            locationManager.delegate = self;
            locationManager.desiredAccuracy=kCLLocationAccuracyBest;
            if([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
                [locationManager requestWhenInUseAuthorization];
            }
            [locationManager startUpdatingLocation];
     
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    - (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
     
        if (
            ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)] && status != kCLAuthorizationStatusNotDetermined && status != kCLAuthorizationStatusAuthorizedWhenInUse) ||
            (![locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)] && status != kCLAuthorizationStatusNotDetermined && status != kCLAuthorizationStatusAuthorized)
            ) {
     
            NSString *message = @"您的手機目前並未開啟定位服務,如欲開啟定位服務,請至設定->隱私->定位服務,開啟本程式的定位服務功能";
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"無法定位"message:message delegate:nil cancelButtonTitle:@"確定" otherButtonTitles: nil];
            [alertView show];
     
        }else {
     
            [locationManager startUpdatingLocation];
        }
    }
  • 相关阅读:
    Android 解决小米手机Android Studio安装app 报错的问题It is possible that this issue is resolved by uninstalling an existi
    Android Unresolved Dependencies
    Android studio 自定义打包apk名
    Android Fragment与Activity交互的几种方式
    魅族和三星Galaxy 5.0webView 问题Android Crash Report
    Android几种常见的多渠道(批量)打包方式介绍
    Android批量打包 如何一秒内打完几百个apk渠道包
    上周热点回顾(9.30-10.6)团队
    上周热点回顾(9.23-9.29)团队
    上周热点回顾(9.16-9.22)团队
  • 原文地址:https://www.cnblogs.com/itlover2013/p/14991978.html
Copyright © 2011-2022 走看看