簡體   English   中英

更改位置服務中的選項

[英]Change the options in location services

在定位服務中,我的應用程序具有三個選項:從不,在使用時和始終。 是否有可能更改這些選項,例如刪除“ While Using選項?

編輯1:

- (void)checkAuth {

    if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {

        if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined) {
            [self.manager requestAlwaysAuthorization];

        } else if ([CLLocationManager authorizationStatus] != kCLAuthorizationStatusAuthorizedAlways) {
            [[[UIAlertView alloc] initWithTitle:@"title" message:@"message" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"Setting", nil] show];
        }
    } else {

        if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined) {
            [self.manager startUpdatingLocation];
            [self.manager stopUpdatingLocation];

        } else if ([CLLocationManager authorizationStatus] != kCLAuthorizationStatusAuthorized) {
            [[[UIAlertView alloc] initWithTitle:@"title" message:@"message" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"Setting", nil] show];
        }
    }
}

這是我用來要求授權的代碼。

我自己找到的。 在info.plist中,當您想請求位置服務授權時,需要一些選項。

<key>NSLocationAlwaysUsageDescription</key>       // 'Always' authorization
    <string>Some message</string>
<key>NSLocationWhenInUseUsageDescription</key>    // 'While in use' authorization
    <string>Some message</string>

如果不需要,請刪除其中任何一個。

您應該只具有您從用戶那里請求的選項(除了從不,這將一直存在,因此他們可以選擇禁用位置服務)。

如果出現While Using ,則可能意味着您正在使用[self.locationManager requestWhenInUseAuthorization]在代碼中的某個[self.locationManager requestWhenInUseAuthorization]

相反,您應該使用[self.locationManager requestAlwaysAuthorization]

編輯:

如果在開發過程中不小心同時請求了兩個位置權限,則可能需要完全刪除該應用程序,然后僅在請求requestAlwaysAuthorization時再次運行它,如上所示。 這將刪除現有權限並重新提示用戶。

是否有可能更改這些選項,例如刪除“使用中”選項?

刪除SDK選項? ->沒有處理嗎? ->是的

基本上,如果您要檢查位置服務的當前狀態,可以像已經檢查狀態一樣使用:

[CLLocationManager authorizationStatus]

根據Apple文檔,它應該返回:

typedef enum {
   kCLAuthorizationStatusNotDetermined = 0,
   kCLAuthorizationStatusRestricted,
   kCLAuthorizationStatusDenied,
   kCLAuthorizationStatusAuthorized,
   kCLAuthorizationStatusAuthorizedAlways = kCLAuthorizationStatusAuthorized,
   kCLAuthorizationStatusAuthorizedWhenInUse 
} CLAuthorizationStatus;

從這一點出發,我認為您擁有處理各種案件所需的一切。 如果要以相同的方式處理Always和WhenInUse,只需在相同的if中使用OR條件進行測試。

如果需要,可以在這里提供更多幫助:

http://nshipster.com/core-location-in-ios-8/

暫無
暫無

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

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