如果应用程序意外关闭,如何重新启动应用程序 [英] How to restart app if it unexpectedly shutdown

查看:71
本文介绍了如果应用程序意外关闭,如何重新启动应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Skype 更新文本包含下一个:

<块引用>

应用程序在意外关闭时自动重启

如何通过 SDK 执行该操作?

解决方案

据我所知,某些应用程序可以在后台运行,并且可以在特定情况下重新启动.这是来自 Apple 文档

https://developer.apple.com/library/ios/#documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html#//apple_ref/doc/uid/TP40007125

<块引用>

如果您启动此服务并且您的应用程序随后被终止,如果有新事件到达,系统会自动将应用程序重新启动到后台.在这种情况下,传递给 application:didFinishLaunchingWithOptions: 应用程序委托方法的选项字典包含键 UIApplicationLaunchOptionsLocationKey 以指示您的应用程序是由于位置事件而启动的.

我的看法是:Skype 重新推出了远程通知机制.

更新

嗯,我想我找到了一些东西.@Malek_Jundi 说对了一半.您的应用应该会因非零退出代码而失败,但它应该被注册为 VoIP 应用.

<块引用>

因为 VoIP 应用程序需要保持运行才能接收来电,如果应用程序以非零退出代码退出,系统会自动重新启动该应用程序.(这可能发生在内存压力导致应用程序终止的情况下.)但是,终止应用程序也会释放其所有套接字,包括用于维护 VoIP 服务连接的套接字.因此,当应用程序启动时,它总是需要从头开始创建它的套接字.

http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html#//apple_ref/doc/uid/TP40007072-CH7-SW12p>

Skype update text contains next:

App auto restarts if unexpectedly shut down

How is possible to perform that via SDK?

解决方案

As far as I know, some sort of apps can be run in background and can be restarted in specific case. This is from Apple docs

https://developer.apple.com/library/ios/#documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html#//apple_ref/doc/uid/TP40007125

If you start this service and your application is subsequently terminated, the system automatically relaunches the application into the background if a new event arrives. In such a case, the options dictionary passed to the application:didFinishLaunchingWithOptions: method of your application delegate contains the key UIApplicationLaunchOptionsLocationKey to indicate that your application was launched because of a location event.

My opinion is: Skype is relaunched with remote notifications mechanism.

Update

Well, I think I found something. @Malek_Jundi was half-right. Your app should fail with non-zero exit code, but it should be registered as VoIP application.

Because VoIP applications need to stay running in order to receive incoming calls, the system automatically relaunches the application if it exits with a nonzero exit code. (This could happen in cases where there is memory pressure and your application is terminated as a result.) However, terminating the application also releases all of its sockets, including the one used to maintain the VoIP service connection. Therefore, when the application is launched, it always needs to create its sockets from scratch.

http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html#//apple_ref/doc/uid/TP40007072-CH7-SW12

这篇关于如果应用程序意外关闭,如何重新启动应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆