sohel14_cse_ju
sohel14_cse_ju

Reputation: 2521

How can I restart my iphone app from an AlertView?

I want to restart my application by alert ok button click. How can I do this?

Upvotes: 2

Views: 316

Answers (3)

user1072740
user1072740

Reputation: 660

You can exit the application via exit(0), and then call a URL which is made in .plist file, and restart your app.

To make the URL, add a row with "URL types", Item 0 is der, In item0 "URL identifier", in url identifier, write "com.provisionalprofiel.AppName", then add URL Shemes in item0, in it insert write "AppName" which you define in URL identifier.

Finally call the url with "AppName:/", and see the magic!

Upvotes: 2

cweinberger
cweinberger

Reputation: 3588

You can't.

(You can only exit your application)

Upvotes: 1

aroth
aroth

Reputation: 54846

The short answer is; you can't if you want to get your app approved by Apple.

The longer answer is to first show your alert:

UIAlertView *alert = [[UIAlertView alloc]
            initWithTitle: @"Restart"
            message: @"Click to restart the application"
            delegate: self
            cancelButtonTitle:@"OK"
            otherButtonTitles:nil];
[alert show];
[alert release];

And make sure that your view-controller is set up to detect when the user clicks the "OK" button:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
        //do stuff here...
}

And then replace //do stuff here... with code to make your application appear that it is restarting. You cannot actually programmatically restart your application (you can quit programmatically by calling exit(), but forcing the app to restart after that is not possible), the best you can do is run some effects to make the user think that that's what happened. How to do that will depend upon what your app looks like/does when it starts up.

Upvotes: 3

Related Questions