IOS 系统定位提示完毕后 提示用户去开启定位权限

来源:互联网 发布:淘宝上冰毒暗语 编辑:程序博客网 时间:2024/06/05 19:35

当用户选择了系统不开启定位提示后,在此处可以然后去提示用户开启定位权限。


当定位失败时,通过定位失败的code来判断是否需要再次弹出提示用户定位的对话框

http://bbs.yusian.com/thread-10617-1-1.html

Code=0说明没有位置信息

Code=1说明是系统授权问题  


- (void)mapLocationDidFailWithError:(NSError *)error{    NSLog(@"----%@",error);        if (error.code == 1)    {        if([[NSUserDefaults standardUserDefaults] boolForKey:@"EachTimeAppStart"])        {            //判断定位服务权限是否开通            [self initCLLocationManager];            [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"EachTimeAppStart"];            [[NSUserDefaults standardUserDefaults] synchronize];        }    }}

- (void)initCLLocationManager{    BOOL enable=[CLLocationManager locationServicesEnabled];    NSInteger status=[CLLocationManager authorizationStatus];    if(!enable || status<3)    {        if ([[UIDevice currentDevice].systemVersion floatValue] >= 8)        {            CLLocationManager  *locationManager = [[CLLocationManager alloc] init];            [locationManager requestAlwaysAuthorization];            [locationManager requestWhenInUseAuthorization];        }                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"打开定位开关"                                                            message:@"定位服务未开启,请进入系统[设置]> [隐私] > [定位服务]中打开开关,并允许使用定位服务"                                                           delegate:self                                                  cancelButtonTitle:nil                                                  otherButtonTitles:@"取消",@"立即开启", nil];        alertView.tag = ALERTTAGNUMBER;        [alertView show];            }}


0 0