在需要使用地理位置的時(shí)候就需要打開(kāi)使用地理位置的權(quán)限.很多時(shí)候用戶在第一時(shí)間就直接關(guān)閉了使用地理位置的權(quán)限,那么用戶使用到了地理位置的時(shí)候就需要提醒用戶去開(kāi)啟權(quán)限:
6CO5L.gif
具體實(shí)現(xiàn)代碼如下:
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];
}
UIAlertController *alertView=[UIAlertController alertControllerWithTitle:@"打開(kāi)定位開(kāi)關(guān)提供更優(yōu)質(zhì)的服務(wù)" message:@"定位服務(wù)未開(kāi)啟,請(qǐng)進(jìn)入系統(tǒng)[設(shè)置]> [隱私] > [定位服務(wù)]中打開(kāi)開(kāi)關(guān),并允許使用定位服務(wù)" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *sureAction=[UIAlertAction actionWithTitle:@"立即開(kāi)啟" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}];
UIAlertAction *cancelAction=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}];
[alertView addAction:sureAction];
[alertView addAction:cancelAction];
[self presentViewController:alertView animated:YES completion:nil];
}
有問(wèn)題可直接咨詢我,歡迎在評(píng)論區(qū)指出不足,或者優(yōu)化建議 承接APP,小程序,公眾號(hào)開(kāi)發(fā). 性價(jià)比高.+V信:17723566468 有單子也可找我一起做哦