2016-06-22 40 views
0

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

EDIT1:

- (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]; 
     } 
    } 
} 

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

回答

2

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

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

如果你不需要,刪除它們中的任何一個。

0

您應該只有從用戶請求的選項(除了永遠不會,永遠在那裏,因此他們可以選擇禁用位置服務)。

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

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

編輯:

櫃面你不小心要求兩國位置許可而開發,你可能要徹底刪除程序,然後再運行它只是請求requestAlwaysAuthorization爲如上所示。這將刪除現有的權限並重新提示用戶。

+1

我檢查過了,沒有地方使用'requestWhenInUseAuthorization'。 –

0

是否有任何更改這些選項的可能性,例如在使用選項時刪除 ?

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

基本上,如果你想查詢的定位服務的當前狀態,您可以使用,像你已經做檢查狀態:

[CLLocationManager authorizationStatus] 

,它應該返回,根據蘋果文檔:

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

從這一點上,我認爲你有你需要處理的不同情況。如果你想以同樣的方式處理Always和WhenInUse,只需在同一個if中使用OR條件進行測試。更

有點幫助在這裏如果需要的話:

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

+0

我可以處理它,但是我的下午表示當應用程序在後臺運行時,他不想在頂部看到「xxx正在使用當前位置」的徽章。該徽章僅在用戶切換到「WhenInUse」選項時顯示。 –