xcode 如何在 iOS 中以编程方式重新启动或重新加载 iPhone 应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9126827/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:12:14  来源:igfitidea点击:

How to reboot or reload iPhone app programmatically in iOS

iphoneobjective-ciosxcodecocoa-touch

提问by Jaume

I have dowloaded an xml filethat contains some update parameters and then I need to reload these parameters and init some views. Easiest way is to apply this configuration on next app boot. Is there any way to reboot iOS applicationprogrammatically?

我已经下载了一个xml file包含一些更新参数的文件,然后我需要重新加载这些参数并初始化一些视图。最简单的方法是在下次应用程序启动时应用此配置。有没有办法以iOS application编程方式重新启动?

Thank you.

谢谢你。

回答by Amit Shah

Rebooting the app is a bad idea, I'm pretty sure Apple would reject it. However, You could display a popup telling the user to open a close the app to apply your updated information. But the best way would be just to manually call the methods needed to rebuild your app (I.e. the ones that need to use the updated data). If you have to do some extensive rebuilding (i.e. things that the user would immediately notice) it might be a good idea to add in a "loading" progress bar of sorts.

重新启动应用程序是一个坏主意,我很确定苹果会拒绝它。但是,您可以显示一个弹出窗口,告诉用户打开关闭应用程序以应用更新的信息。但最好的方法是手动调用重建应用程序所需的方法(即需要使用更新数据的方法)。如果您必须进行一些广泛的重建(即用户会立即注意到的事情),添加各种“加载”进度条可能是个好主意。

回答by sosborn

You can't reboot your app, and I don't see why you would a) have to b) EVER WANT TO.

你不能重启你的应用程序,我不明白你为什么 a) 必须 b) 曾经想要。

回答by hotpaw2

You can quit and restart an iOS app with a bit of user assistance. Set the app's plist key for application exits on suspend. Create a local notification for your app to trigger a few seconds into the future. Then send Safari a URL. The OS will terminate your app when launching Safari to handle the URL. The URL might be to a web landing page telling the user that a relaunch is in progress. Then the local notification will go off and ask the user to relaunch your app.

您可以在一些用户帮助下退出并重新启动 iOS 应用程序。为应用程序在挂起时退出设置应用程序的 plist 键。为您的应用创建本地通知,以在未来几秒钟内触发。然后向 Safari 发送一个 URL。当启动 Safari 处理 URL 时,操作系统将终止您的应用程序。URL 可能是一个网页登陆页面,告诉用户重新启动正在进行中。然后本地通知将关闭并要求用户重新启动您的应用程序。

However an app should be (re)designed so that there is never a reason to do this.

但是,应用程序应该(重新)设计,以便永远没有理由这样做。

回答by Vivek

You can do it only if your device is jailbroken

仅当您的设备已越狱时才能执行此操作

Put a reboot button in your app and call abort();. This will crash the app.

在您的应用程序中放置一个重启按钮并调用abort();. 这将使应用程序崩溃。

Hook the -(void)exitedAbnormally; from SBApplicationand write code to launch your app.

挂钩-(void)exitedAbnormally; 从SBApplication并编写代码以启动您的应用程序。

If its not jailbroken, you have no choice

如果没有越狱,你别无选择

回答by Radu Ursache

if you develop for jailbroken devices you can use uicachecommand to clean the springboard cache and reload new apps/icons (available from UIKit package).

如果您为越狱设备开发,您可以使用uicache命令来清理跳板缓存并重新加载新的应用程序/图标(可从 UIKit 包获得)。

for example,

例如,

1) if you're under root:

1) 如果您是 root 用户:

    su mobile -c uicache 1>/dev/null 2>&1

2) if you're under mobile:

2)如果您使用手机:

    uicache

for reboot you can use rebootcommand under root and killall SpringBoardfor respring

对于重新启动,您可以reboot在 root 和killall SpringBoardrespring下使用命令