Question

When I launch my application on my device, while being connected to Xcode, it works perfectly. When I launch it again after removing it from the multitask, on the iPhone, (so without clicking the run button on Xcode), it doesn't work well anymore.

What works is :

In my viewDidLoad, I call [self retrieveData];

Here is retrieveData method : It is getting data from web : It works perfectly when connected to Xcode and when not.

But when I launch the app from the iPhone without launching it from the Run button on Xcode's interface, then the locationManager: didUpdateTolocation method is not called properly because my application doesn't behave properly.

Additional informations for better understanding : On iPhone Simulator the pop up shows. On iOS device while being launched from Xcode the pop up shows. I don't know why when I launch from the iPhone without Xcode and the cable the pop up doesn't show and I guess the didUpdateToLocation doesn't work properly. Any idea ?

Edited post reference to comment :

#pragma mark - Update Location
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{

    CLLocation *currentLocation = newLocation;
    NSLog(@"didUpdateToLocation: %@", newLocation);

    if (currentLocation != nil) {
        // On affiche la longitude et latitude
        longitudeLabel.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude];
        latitudeLabel.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude];

        CLLocation *userLocation = [[CLLocation alloc] initWithLatitude:currentLocation.coordinate.latitude longitude:currentLocation.coordinate.longitude];

        float distance = [userLocation distanceFromLocation:locDatabase];
        NSLog(@"la distance est de : %f", distance);
        if(distance<0.03)
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Joleju" message:@"Vous entrez dans la zone!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alert show];
        }

        // ---------------------------------------------------------------------------------------------------------------------------

        // Reverse Geocoding
        NSLog(@"Resolving the Address");
        [geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) {
            NSLog(@"Found placemarks: %@, error: %@", placemarks, error);
            if (error == nil && [placemarks count] > 0) {
                placemark = [placemarks lastObject];
                adressLabel.text = [NSString stringWithFormat:@"%@ %@\n%@ %@\n%@\n%@",
                                    placemark.subThoroughfare, placemark.thoroughfare,
                                    placemark.postalCode, placemark.locality,
                                    placemark.administrativeArea,
                                    placemark.country];
            } else {
                NSLog(@"%@", error.debugDescription);
            }
        } ];

    }
}
Was it helpful?

Solution

Is this being called in viewDidLoad of your Main/Root/MasterViewController? (The one that is launched from your AppDelegate). If so, this method will only be called when the app first launches, not when it resumes from background. As an experiment, move the method call [self retrieveData] to viewWillAppear:

Edited Answer from more information: It's possible that your alert view show method is being called from a background thread and while you're in debug mode, it's still working, but as soon as you launch without the debugger, it's getting lost. UI methods should always be called from the main thread, so put a break point on the [alert show] line and see what thread it is using. To fix it, change the line to [alert performSelectorOnMainThread:@selector(show)]. I hope this finally solves your problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top