ios - 无法重新启用我的应用中的位置

标签 ios objective-c xcode xib

我有一个按钮操作,其中核心定位方法有效

我只想在我不允许位置时再次单击按钮,然后出现UIAlertView,它再次询问允许位置

我不知道输入的代码允许我再次定位。谁来帮帮我

兔子是我的源代码的示例-

 
 - (IBAction)geolocation:(id)sender { 
    if([CLLocationManager locationServicesEnabled] &&
       [CLLocationManager authorizationStatus] != kCLAuthorizationStatusDenied) {
        // show the map
       
    NSString *parameter = [NSString stringWithFormat:@"lat=%@&long=%@",lati,longs];
    
    NSURL *url_ = [[NSURL alloc]initWithString:[NSString stringWithFormat:@"http://***/near_by_api.php"]];
    
    NSData *postData = [[NSString stringWithFormat:@"%@",parameter] dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    
    NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]];
    
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    [request setURL:url_];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:postData];
    
    NSError *error = [[NSError alloc] init];
    NSHTTPURLResponse *response = nil;
    NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    
    if (urlData) {
             
        record = [NSMutableArray array];
        record = [NSJSONSerialization JSONObjectWithData:urlData options:kNilOptions error:nil];
        
        [self.view addSubview:third_view];
        [third_view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
        [third_tbl_view reloadData];
    }}else{
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Location Service Disabled" message:@"Allowed location?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil];
        [alert show];
    }
    
    
    
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0)
    {
      //code for cancel
        

    }
    if (buttonIndex == 1)
    {
        //Code for ok button
        
        
                   }
}

最佳答案

如果您不允许位置,则下次必须在设置中手动激活位置。您可以通过以下方式打开设置:

if (&UIApplicationOpenSettingsURLString != NULL) {
   NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
    [[UIApplication sharedApplication] openURL:url];
}
else {
  // Present some dialog telling the user to open the settings app.
}

关于ios - 无法重新启用我的应用中的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38200360/

相关文章:

iphone - 如何构建iOS应用以供一些测试人员下载

ios - 带有图像的 UITableview 滚动速度非常慢

objective-c - 将文字字符串分配给具有 "="的 NSString 实际上有什么作用?

ios - 正确释放返回的 UIImage

ios - 如何准确检测设备型号?

iphone - 核心图gridLines无法使虚线正常工作?

ios - 如何在 Swift 中创建边缘?

ios - FBWebDialogs 添加本地镜像到参数

iphone - 如何使用 didFinishPickingMediaWithInfo 从视频中查找 "Selected frames"的开始和结束持续时间?

ios - 上传高分 - 如何让它只对 friend 可见?