簡體   English   中英

無法重新啟用我的應用中的位置

[英]Unable to re-enable location in my app

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

我只想在我不允許位置時再次單擊按鈕,然后出現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.
}

暫無
暫無

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

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