2

So here is the issue I am facing. Certain portions of the application I am building open some c network sockets that allow connections to various servers/services. However, if the application goes to sleep, these socket connections are lost, and error out when trying to reload them. So what I want to do is basically notify the user when the app launches again, that the application needs to be restarted. The main question is, can I present them with a button that will kill the app by using exit(0) without my app getting rejected?

Apple says that the user should be in control of when the app is killed, and in this case I see that they are, but I am not sure of Apple's opinion on this. Has anyone else used this? Have you been rejected for this? Thanks in advance for any advice!

EDIT:

Thank you everyone for your advice. I am trying to take everything into consideration, but because the app needs to be submitted ASAP, I just need to know, if we can not get another solution, if the above proposed solution, will get rejected or not.

4

4 回答 4

4

当重大事件影响应用程序的生命周期时,您的应用程序委托会收到通知。与其要求您的用户重新创建会话,不如尝试停止网络操作,然后在应用程序生命周期中的适当时间自动恢复它们。

当应用程序准备退出或通过应用程序委托中的回调进入后台时,您可以在任意数量的地方优雅地终止网络套接字(除其他外):

applicationWillResignActive:
applicationWillEnterBackground:
applicationWillTerminate:

可能在以下位置重建套接字:

applicationDidBecomeActive
applicationWillEnterForeground
于 2012-04-21T21:29:35.013 回答
3

您是否尝试过不允许应用在后台运行?然后,只要用户退出主屏幕,它就会被杀死。这可能有点激进,但可以解决问题。从 Apple 选择退出后台执行:

“如果您不希望应用程序在退出时保留在后台,您可以通过将 UIApplicationExitsOnSuspend 键添加到应用程序的 Info.plist 文件并将其值设置为 YES 来明确选择退出后台执行模型。

当应用程序选择退出时,它会在未运行、非活动和活动状态之间循环,并且永远不会进入后台或挂起状态。

当用户点击 Home 按钮退出应用程序时,应用程序委托的 applicationWillTerminate: 方法被调用,应用程序有大约 5 秒的时间清理并退出,然后终止并移回未运行状态。”

另请参阅:如何防止我的应用在 iPhone 的后台运行

于 2012-04-21T21:26:10.210 回答
1

文档对此非常明确,“没有提供用于优雅终止 iOS 应用程序的 API。” 请参阅技术问答 QA1561 如何以编程方式退出我的 iOS 应用程序?.

坦率地说,终止应用程序以清理套接字就像通过强制应用程序退出而不是调用来处理内存管理一样release

于 2012-04-22T00:04:23.533 回答
0

调出一个模态视图控制器告诉用户退出应用程序怎么样?你可以在没有任何关闭按钮的情况下制作这个视图控制器,因此用户有义务终止应用程序。

于 2012-04-21T21:25:12.447 回答