The app that I’m currently working on has a problem propagating settings, but seems to work fine once it’s been closed and re-opened. It’s an alarm clock application so it doesn’t benefit from multi-tasking. Since I am using NSUserDefaults to save pertinent settings, I have shut off multitasking:
@implementation MyAppDelegate
- (void) applicationDidEnterBackground:(UIApplication *)application {
exit(0);
}
...
@end
So at this point the user has to manually close and re-open the app. Is there a command I can send to cause the app to close and re-open (automatically)? I would like the app to close and re-open if certain settings are changed when the settings view controller is removed from the screen.
No, you cannot force an app to restart itself. Using
exit()in your code violates Apple HIG.To accomplish what you want, I suggest showing an alert to the user when the settings are changed, which will advise then that the settings will take effect on next launch.
You should disable multitasking by adding UIApplicationExitsOnSuspend to your info.plist and set it to true.