ios7 ios8 定位兼容性有关问题解决方案

ios7 ios8 定位兼容性问题解决方案

最近开发的app定位功能在ios8上能够正常运行,但是到了ios7的机器上就不能正常运行了,原因是两个系统的定位有些不一样,针对不同的系统是需要做一些处理的。一下是我的一些处理方法。

@property(nonatomic, strong) CLLocationManager * locMgr;
- (CLLocationManager *)locMgr
{
    if (_locMgr == nil) {
        self.locMgr = [[CLLocationManager alloc]init];
        self.locMgr.delegate = self;
    }
    return _locMgr;
}
- (void)init
{
    if ([CLLocationManager locationServicesEnabled]) {
        //IOS8以及以上版本需要设置,弹出是否允许使用定位提示
        if (IOS8_OR_LATER) {
            [self.locMgr requestAlwaysAuthorization];
        }
        [self.locMgr startUpdatingLocation];
        self.locMgr.distanceFilter = kCLDistanceFilterNone;
        self.locMgr.desiredAccuracy=kCLLocationAccuracyBestForNavigation;
    } else {
        //提醒用户打开定位开关
        UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示?" message:@"亲!您还没有打开定位服务哦!请前往设置打开定位服务!" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        [alert show];
    }
}

#pragma mark - CLLocationManagerDelegate

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    //locations数组里边存放的是CLLocation对象,一个CLLocation对象就代表着一个位置
    CLLocation *loc = [locations firstObject];
    //维度:loc.coordinate.latitude
    //经度:loc.coordinate.longitude
    NSLog(@"纬度=%f,经度=%f",loc.coordinate.latitude,loc.coordinate.longitude);
    NSLog(@"%d",locations.count);


    LOCATION * loca = [[LOCATION alloc] init];
    loca.lat = [NSString stringWithFormat:@"%f",loc.coordinate.latitude];
    loca.lng = [NSString stringWithFormat:@"%f",loc.coordinate.longitude];
    self.defaultShopListModel.filter.location = loca;
    self.hotShopListModel.filter.location = loca;
    self.nearShopListModel.filter.location = loca;
    [self updateDatas];
    [self updateViews];

    //停止更新位置(如果定位服务不需要实时更新的话,那么应该停止位置的更新)
    [self.locMgr stopUpdatingLocation];
}

当然还需要在工程目录中设置一些
ios7 ios8 定位兼容性有关问题解决方案

版权声明:本文为博主原创文章,未经博主允许不得转载。