iOS 檢測(cè)是否開(kāi)啟定位,自動(dòng)跳轉(zhuǎn)去開(kāi)啟定位界面

在需要使用地理位置的時(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  有單子也可找我一起做哦
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 173,269評(píng)論 25 708
  • 最近連續(xù)讀了第二本勵(lì)志書(shū)籍了,感覺(jué)十分受用,將即時(shí)得到的好方法直接運(yùn)用生活中,很有效果! 這第一大收獲就是要去分享...
    taoyecumt閱讀 197評(píng)論 1 1
  • 優(yōu)勢(shì) babun集成了cygwin與oh-my-zsh,尤其是后者,意味著如果你同時(shí)擁有Win + MAC雙系統(tǒng)的...
    我的二道橋閱讀 8,709評(píng)論 0 3
  • 生活中有太多的誘惑,每次逛街總會(huì)看到心儀的商品,是拼盡全力都買(mǎi)回家?還是咬緊牙關(guān)什么都不買(mǎi)?以往,我的處理方案是挑...
    I_believe_I_can閱讀 440評(píng)論 0 0