Sending latitude and longitude coordinates to the didFinishLaunchingWithOptions in the app delegate
I have a this function to grab the lat and long in my app delegate, and it's working fine:
- (void)newPhysicalLocation:(CLLocation *)location {
// Store for later use
self.lastKnownLocation = location;
// Remove spinner from view
for (UIView *v in [self.viewController.view subviews])
{
if ([v class] == [UIActivityIndicatorView class])
{
[v removeFromSuperview];
break;
}
}
// Alert user
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Location Found" message:[NSString stringWithFormat:@"Found physical location. %f %f", self.lastKnownLo开发者_JAVA百科cation.coordinate.latitude, self.lastKnownLocation.coordinate.longitude] delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
[alert release];
currentLatitude = (self.lastKnownLocation.coordinate.latitude);
NSLog(@"current latitude: %f",self.lastKnownLocation.coordinate.latitude);
currentLongitude = (self.lastKnownLocation.coordinate.longitude);
NSLog(@"current longitude: %f",currentLongitude);
}
However, I'm trying to send the currentLatitude and currentLongitude values to the top of the app delegate in the didFinishLaunchingWithOptions section. I'm trying to do this so I can pass those values to another viewController in which I have set up:
MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
Can I send the currentLatitude and currentLongitude values to the didFinishLaunchingWithOptions section?
Why not create a currentLatitude
and currentLongitude
in the second viewController?
You can use
- (void)newPhysicalLocation:(CLLocation *)location {
// your code here
SecondViewController *viewController = [[SecondViewController alloc] init];
[viewController setLatitude: currentLatitude andLongitude: currentLongitude];
}
or just
[viewController setCurrentLatitude: currentLatitude];
[viewController setCurrentLongitude: currentLongitude];
From what I understood from your question, you want to pass those coordinate values to another view controller. If thats the case u can make the currentLatitude
and currentLongitude
as class variables of the app delegate. Then when u call this function in applicationDidFinishLaunchingWithOptions:
you can assign the values to these class variables. Then u can access these variables anywhere through an instance of the app delegate.
Note: You have to synthesize the variables if u want to access them outside the class.
Hope this helps
精彩评论