且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检测发送到其他应用程序的推送通知?

更新时间:2023-01-01 15:55:33

您无法检测到发送到另一个应用的推送通知.

You cannot detect a push notification sent to another app.

如果你想检测你的应用是否不再处于前台,你可以使用UIApplicationDelegateapplicationWillResignActive:方法或注册UIApplicationWillResignActiveNotification代码>通知.

If you want to detect whether your app is not in foreground anymore, you can use the applicationWillResignActive: method of UIApplicationDelegate or register for the UIApplicationWillResignActiveNotification notification.

但是,当通知横幅出现在顶部时,您的应用程序仍处于前台.当通知被提示为警报时(用户可以在首选项中设置),应用程序将失去焦点并且不再处于前台.

However, when the notification banner appears on top, your application is still in foreground. When the notification is prompted as an alert instead (the user can set this in the preferences), the application loses the focus and it won't be in foreground anymore.