2016-01-23 54 views
-1

我在IOS新启用位置服务,我想知道我可以通过编程启用位置服务,当我使用这个下面....希望通过Xcode的

enter image description here

由于我使用这个标签来显示每当位置服务被禁用和一个启用按钮(绿色)来启用位置服务。但如何以编程方式。我将如何知道位置服务被禁用,以及按钮如何启用this.Please帮帮我。

+0

请在提问前阅读规则 –

+0

Zoho,你可以把我的链接 –

回答

1

您可以使用CLLocationManager的locationServicesEnabled属性来检查系统范围/整体可用性。使用您的CLLocationManagerDelegate的locationManager:didFailWithError:方法并检查kCLErrorDenied错误以查看用户是否拒绝了位置服务。

if([CLLocationManager locationServicesEnabled]){ 

      NSLog(@"Location Services Enabled"); 

      if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusDenied){ 
       [[[UIAlertView alloc] initWithTitle:@"App Permission Denied" 
                 message:@"To re-enable, please go to Settings and turn on Location Service for this app." 
                 delegate:nil 
               cancelButtonTitle:@"OK" 
               otherButtonTitles:nil]show]; 

      } 
     } 

选择-2

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error 
{ 

    NSLog(@"%@",error); 
} 

if location service disable for your app then its give you error

Error Domain=kCLErrorDomain Code=1 "The operation couldn’t be completed. (kCLErrorDomain error 1.)"

更新

如果用户拒绝许可,我们不能以编程方式启用,用户可以手动启用位置服务,为更多reference

+0

欢迎我的兄弟... –

+0

我也可以使用if(kCLAuthorizationStatusRestricted){UIAlertView};这也是为了控制权利? –

+0

雅兄弟但不否认.. –