当应用程序处于事件状态时,如何处理推送通知点击?
didReceiveRemoteNotification userInfo: [AnyHashable : Any]
当 iOS 设备收到推送通知时调用,当用户点击通知时调用相同的函数。我如何在这个函数中区分这个函数是如何调用的?我正在使用推送通知的 OneSignal
,以防有必要了解问题。
最佳答案
OneSingal
有闭包通知您通知和用户操作。这就是我使用它的方式
func initOneSignalNotifications(withLaunchOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) {
let onesignalInitSettings = [kOSSettingsKeyAutoPrompt: false]
OneSignal.initWithLaunchOptions(launchOptions, appId: Constants.oneSignalKey, handleNotificationReceived: { (receivedNotification) in
//Notification is received
}, handleNotificationAction: { (notificationResult) in
//Notification was tapped
}, settings: onesignalInitSettings)
OneSignal.inFocusDisplayType = OSNotificationDisplayType.notification;
OneSignal.promptForPushNotifications(userResponse: { accepted in
FileHandler.log(message: "Notification permission granted: \(accepted)", tag: .application, logLevel: .info)
})
}
此处 inFocusDisplayType
表示当您的应用打开时,OneSignal
仍会显示通知。
关于iOS 在应用程序处于事件状态时处理推送通知点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57196217/