2016-07-05 4 views
1

i eine Schaltfläche Aktion haben, in dem Kernlokalisierungsverfahrenkann nicht wieder aktivieren Lage in meiner app

arbeiten ich möchte nur, wenn ich erlauben don "t Lage und wieder Schaltfläche klicken dann erscheint UIAlertView, in dem es wieder fragen nach ermöglichen erlauben Standort

ich weiß nicht, welchen Code ich wieder erlauben meine Lage versetzen. jemand mir helfen

Hase ist die Probe meiner Quelle Code-

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

Antwort

2

Wenn Sie den Standort nicht zulassen, müssen Sie den Standort das nächste Mal manuell in den Einstellungen aktivieren. Sie können Einstellungen auf diese Weise öffnen:

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