2016-06-22 41 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”选项时显示。 –