Reply to comment

Clear location service object in resign active

Since iOS 4.0, I am aware freeing unnecessary object when the application is in inactive state so that the app can free up as much memory as possible. So in one of me location based app, I try to free the location service object when it is inactive:


- (void)applicationWillResignActive:(UIApplication *)application {
self.locationService = nil;
....
/*
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
*/
}

It is a big mistake! When you called the [self.locationService startUpdatingLocation], in the first several trial, the system will prompt user for allowing the location service for this app. When the dialog is popup, the application is actually switched to inactive state, and applicationWillResignActive will be called. If you free the location service object, the dialog will be closed immediately and the process will failed.

Reply

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.