私が設定しているNSLocationAlwaysUsageDescription
とNSLocationWhenInUseUsageDescription
では、info.plist
アプリが位置情報サービスを利用したい場合、アラートが表示されますが、アラートはほんの少しの時間のために表示され、私はこのアラートをクリックすることはできません。このアラートは自動的に消えます!
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)
{
}
次のコードを試してください。それは私のために働いた
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加