zoukankan      html  css  js  c++  java
  • iOS8 定位补充

    iOS 8定位补充

    iOS 8定位需要修改2个地方

    1.info.plist文件中添加NSLocationAlwaysUsageDescription:描述信息

    从iOS 8开始,用户定位分两种情况
    总是使用用户位置:NSLocationAlwaysUsageDescription
    使用应用时定位:NSLocationWhenInUseDescription

    2.在CLLocationManager中调用

    - (void)requestAlwaysAuthorization

    - (void)requestWhenInUseAuthorization

    #import "ViewController.h"
    #import <CoreLocation/CoreLocation.h>
    
    @interface ViewController () <CLLocationManagerDelegate>
    
    @property(nonatomic,strong)CLLocationManager *mgr;
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        
        [self.mgr startUpdatingLocation];
        
        // 如果是iOS8,需要请求授权方式(进行判断,否则在iOS7会崩溃,需要先在info.plist中配置)
        // 1.通过判断系统判断来确定是否需要请求requestAlwaysAuthorization授权
    //    if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) {
    //        [self.mgr requestAlwaysAuthorization];
    //    }
        // 2.通过判断是否有该方法来判断是否需要请求requestAlwaysAuthorization授权
        if ([self.mgr respondsToSelector:@selector(requestAlwaysAuthorization)]) {
            [self.mgr requestAlwaysAuthorization];
        }
    }
    
    - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
    {
        NSLog(@"获取到用户的位置");
    }
    
    - (CLLocationManager *)mgr
    {
        if (_mgr == nil) {
            _mgr = [[CLLocationManager alloc] init];
            _mgr.delegate = self;
        }
        
        return _mgr;
    }
    
    @end
  • 相关阅读:
    网络流24题
    Preliminaries for Benelux Algorithm Programming Contest 2019
    2019 ICPC Asia Xuzhou Regional
    2019 ICPC Asia Nanjing Regional
    后缀自动机学习
    2018 ACM-ICPC 焦作区域赛 E Resistors in Parallel
    2019 ICPC 上海区域赛总结
    LA 3641 Leonardo的笔记本 & UVA 11077 排列统计
    UVA 10294 项链与手镯 (置换)
    CF 1288 E. Messenger Simulator
  • 原文地址:https://www.cnblogs.com/HJiang/p/4345060.html
Copyright © 2011-2022 走看看