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);
}
} ];
}
}