I am trying to use my appDelegate to get a user’s location from another view. I could save it in NSUserDefaults, but I was wondering if there is a better way to do it.
My AppDelegate contains this:
- (NSString *)deviceLocation
{
NSString *userCoordinates = [NSString stringWithFormat:@"latitude: %f longitude: %f",
locationManager.location.coordinate.latitude,
locationManager.location.coordinate.longitude];
locationManager = [[CLLocationManager alloc] init];
locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[locationManager startUpdatingLocation];
return userCoordinates;
}
Then I want to call the user’s location from another page with this:
//Get the User's Location
NSString *location =[(PDCAppDelegate *)[UIApplication sharedApplication].delegate deviceLocation];
This don’t work because the deviceLocation method in the AppDelegate don’t return anything.
If you want to alert your current location the deviceLocation should return something (i.e a NSString with the current location).
Then display it with something like this