簡體   English   中英

提醒iOS 9中的位置服務許可

[英]Alert for permission of location service in iOS 9

我已經在info.plist設置了NSLocationAlwaysUsageDescriptionNSLocationWhenInUseUsageDescription ,該警報在應用程序要使用位置服務時出現,但是該警報僅出現了一段時間,我無法單擊此警報。 該警報自動消失!

 func showLocation(sender: UIButton)
    {
        let manager = CLLocationManager()
        manager.delegate = self
        if CLLocationManager.authorizationStatus() != CLAuthorizationStatus.AuthorizedAlways
        {
            manager.requestWhenInUseAuthorization()
        }
        manager.startUpdatingLocation()
    }
    func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        for location in locations {
            print("The location is (location)")
        }
    }
self.locationManager = [[CLLocationManager alloc]init];
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined)
{
    if([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"] && [self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]){
        [self.locationManager requestWhenInUseAuthorization];
    }
}
else if([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied)
{
    //Location Services is off from settings

}
else if([CLLocationManager authorizationStatus] == kCLAuthorizationStatusRestricted)
{

}

嘗試以下代碼。 對我有用

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM