How to terminate the iPhone application?

or "How to simulate a button press on a home button?"

I need to restart the application for the iPhone, and I want the program to exit, so the user only needs to start it.

If I just use exit(0), some changes will not be saved, as if the user left by pressing the home button.

Restart required to change the language.

Associated Code:

- (void)onChangeLanguage: (id)sender {
    NSArray *lang = [NSArray arrayWithObjects:((Whatever *)sender).newLanguage, nil];
    [[NSUserDefaults standardUserDefaults] setObject:lang forKey:@"AppleLanguages"];
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSArray *languages = [defaults objectForKey:@"AppleLanguages"];
    NSString *currentLanguage = [languages objectAtIndex:0];

    NSLog(@"Current language: %@", currentLanguage);
    // ***
}   

If the user restarts using the home button, the language will change.

If // ***replaced by exit(0), the language will not change.

+3
source share
3 answers

, exit, [[NSUserDefaults standardUserDefaults] synchronize], . synchronize Apple Documentation:

, , ( , ) , .

+5

exit(0) ( ) .
UIAlertView , ( ) , , .

+7

, API-. , API .

[[UAppication sharedApplication] terminate];

+3

Source: https://habr.com/ru/post/1722442/


All Articles