简体   繁体   English

如何从AlertView重新启动我的iPhone应用程序?

[英]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? 我怎样才能做到这一点?

The short answer is; 简短的答案是: you can't if you want to get your app approved by Apple. 如果您想让您的应用程序被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. 然后用代码替换//do stuff here... ,以使您的应用程序似乎正在重新启动。 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. 您实际上无法以编程方式重新启动应用程序(可以通过调用exit()来以编程方式exit() ,但是无法在此之后强制重新启动应用程序),您可以做的最好的事情就是运行某些效果以使用户认为发生了这种情况。 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. 您可以通过exit(0)退出应用程序,然后调用在.plist文件中创建的URL,然后重新启动应用程序。

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. 要创建URL,请添加带有“ URL类型”的行,项目0为der,在项目0“ URL标识符”中,在URL标识符中,写入“ com.provisionalprofiel.AppName”,然后在项目0中添加URL Shemes,在其中插入写入您在URL标识符中定义的“ AppName”。

Finally call the url with "AppName:/", and see the magic! 最后,使用“ AppName:/”调用该网址,然后看一下魔术吧!

You can't. 你不能

(You can only exit your application) (您只能退出您的应用程序)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM