ios8 CLLOcationManager 定位与ios7的对比

本文介绍了如何在iOS8中正确配置应用的定位服务权限,包括在info.plist中添加必要的键值以及更新CLLocationManager实例化的步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ios8在app进行定位的问题上,同ios7 有了一些不同,在ios7当中,只要 对CLLocationManager 类进行实例化,即:

    self.locationManager = [[CLLocationManager alloc] init];
    [self.locationManager setDelegate:self];
    [self.locationManager startUpdatingLocation];

在ios8当中,需要在工程的info.plist文件中添加NSLocationWhenInUseUsageDescription和NSLocationAlwaysUsageDescription两个键值,对应的变量设为YES

同时在实例化时:

  self.locationManager = [[CLLocationManager alloc] init];
    [self.locationManager setDelegate:self];
      [self.locationManager requestAlwaysAuthorization];
    [self.locationManager startUpdatingLocation];

添加

      [self.locationManager requestAlwaysAuthorization];


这样就可以在ios8当中进行系统定位了

delegate 需要添加的方法还是:

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值