[英]Location Services Stop working after reinstall with iOS10
卸載iOS10應用后,定位服務停止工作。 我已經在Info.plist中設置了說明,因此使我困惑為什么定位服務將停止工作。 該應用程序未顯示在“設置”->“隱私”->“位置服務”中
<key>NSLocationAlwaysUsageDescription</key>
<string>This app needs to use your location so that it may send it to your selected contacts.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>This app needs to use your location so that it may send it to your selected contacts.</string>
使用以下代碼檢查狀態將顯示狀態未確定。
if ([CLLocationManager locationServicesEnabled]) {
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusRestricted) {
NSLog(@"RESTRICTED");
} else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) {
NSLog(@"DENIED");
} else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined) {
NSLog(@"NOT DETERMINED");
} else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedAlways) {
NSLog(@"ALWAYS");
} else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse) {
NSLog(@"WHEN IN USE");
}
}
編輯: viewController viewDidLoad方法包含以下代碼:
- (void)viewDidLoad {
[self.locationManager requestAlwaysAuthorization];
[self.locationManager requestWhenInUseAuthorization];
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.delegate = self;
if ([CLLocationManager locationServicesEnabled]) {
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusRestricted) {
NSLog(@"RESTRICTED");
} else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) {
NSLog(@"DENIED");
} else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined) {
NSLog(@"NOT DETERMINED");
} else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedAlways) {
NSLog(@"ALWAYS");
} else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse) {
NSLog(@"WHEN IN USE");
}
}
}
您需要使用[yourLocationManager startUpdatingLocation]
,這將提示使用位置的警報。
在此之前, authorizationStatus
將為kCLAuthorizationStatusNotDetermined
編輯
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[self.locationManager requestAlwaysAuthorization];
self.locationManager.delegate = self;
加上這個
您需要檢查授權狀態,如果它是xxx,則需要調用requestAlwaysAuthorization()
或requestWhenInUseAuthorization()
。 這將向用戶觸發警報。
如果您通過長按應用程序圖標並點按X來刪除該應用程序,則會撤消用戶使用位置服務的權限,因此該應用程序將被拒絕訪問,直到您再次調用requestAlwaysAuthorization()
或requestWhenInUseAuthorization()
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.