How to terminate an app programmatically in iOS 12

前端 未结 2 936
不知归路
不知归路 2021-02-06 00:34

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.

相关标签:
2条回答
  • Try this code :

    DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
        UIApplication.shared.perform(#selector(NSXPCConnection.suspend))
         DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
          exit(0)
         }
    }
    

    This will wait 1 sec and app will take 0.5 second to close. You can dim display before this code snippet.

    0 讨论(0)
  • 2021-02-06 01:12

    You can call exit method

    exit(-1)
    

    or you can use NSXPCConnection.suspend

    UIControl().sendAction(#selector(NSXPCConnection.suspend),
                           to: UIApplication.shared, for: nil)
    

    Besides Apple isn't recommending to force terminate your app. It doesn't matter how you do that.

    Check this post.

    0 讨论(0)
提交回复
热议问题