如何在iOS 12中以编程方式终止应用 [英] How to terminate an app programmatically in iOS 12
问题描述
我有一个问题,我将iPhone 6放在iOS 12 beta 1上,因此当我按下弹出按钮时,我的应用程序中的一种关闭方法在iOS 12上不起作用,但在iOS 11.4.1上起作用
I have a problem I put my iPhone 6 on iOS 12 beta 1 and that's so a method in my application to close when press on a popup button doesn't works on iOS 12 but works on iOS 11.4.1
这就是我使用的方法:
UIControl().sendAction(#selector(URLSessionTask.suspend), to: UIApplication.shared, for: nil)
在iOS 11中,该应用程序可以正常退出,在iOS 12中,该应用程序不会退出,只需按一下弹出按钮即可.
In iOS 11 the app exit properly, in iOS 12 the app doesn't exit just do nothing when press on the popup button.
我知道这是Swift 4.2,当我发布新闻和修改内容时,我还没有看到类似链接的链接,该链接与一种新方法可以正确关闭应用程序.
I know that this is Swift 4.2 and when I rode the news and modifications I haven't seen something like a link with a new method to close app properly.
我需要这样做,因为如果该人不接受条款和条件,我会用它来关闭应用程序.
I need that because I use that to close the app if the person doesn't accept Terms and conditions.
推荐答案
您可以调用退出方法
exit(-1)
或者您可以使用 NSXPCConnection.suspend
UIControl().sendAction(#selector(NSXPCConnection.suspend),
to: UIApplication.shared, for: nil)
此外,Apple不建议强制终止您的应用程序.没关系,怎么做.
Besides Apple isn't recommending to force terminate your app. It doesn't matter how you do that.
检查此帖子.
这篇关于如何在iOS 12中以编程方式终止应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!