开发者

How can I restart my iphone app from an AlertView?

I want to restart my application by alert ok button click. How开发者_Python百科 can I do this?


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.


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!


You can't.

(You can only exit your application)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜