如何在应用程序中强制执行 UIApplication DidEnterBackgroundNotification

How to force UIApplicationDidEnterBackgroundNotification in app

我真的不确定我们是否可以从应用程序 post UIApplicationDidEnterBackgroundNotification

假设我有一个带按钮的示例应用程序,当我点击按钮时它应该 post UIApplicationDidEnterBackgroundNotification 通知。

真的可以吗?

 UIApplication.shared.perform(#selector(NSXPCConnection.suspend))

its working but may be its violate apple's guidline.

Quitting your application or sending it to the background programmatically is a violation of the [iOS Human Interface Guidelines][1], which usually doesn't bode well for getting through the review process.