Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当应用程序处于活动状态时,点击iOS处理推送通知_Ios_Push Notification_Onesignal - Fatal编程技术网

当应用程序处于活动状态时,点击iOS处理推送通知

当应用程序处于活动状态时,点击iOS处理推送通知,ios,push-notification,onesignal,Ios,Push Notification,Onesignal,当应用程序处于活动状态时,如何处理推送通知点击? didReceiveRemoteNotification用户信息:[AnyHashable:Any]在iOS设备收到推送通知时调用,在用户点击通知时调用相同的函数。我如何在这个函数中区分这个函数是如何调用的?我正在使用推送通知的OneSignal,以防有必要了解问题。如果您的目标高于iOS 10,您可以处理点击 func userNotificationCenter ( _ center : UNUserNotificationCenter, d

当应用程序处于活动状态时,如何处理推送通知点击?
didReceiveRemoteNotification用户信息:[AnyHashable:Any]
在iOS设备收到推送通知时调用,在用户点击通知时调用相同的函数。我如何在这个函数中区分这个函数是如何调用的?我正在使用推送通知的
OneSignal
,以防有必要了解问题。

如果您的目标高于iOS 10,您可以处理点击

func userNotificationCenter ( _ center : UNUserNotificationCenter, didReceive
response : UNNotificationResponse, withCompletionHandler completionHandler :
@escaping () -> Void ) {
        // perform notification received/click action as per third party SDK as per their document
    }
}

否则,您需要使用
didReceiveMotonification userInfo:[AnyHashable:Any]
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
仍将显示通知。

保存标志当您的应用程序将重新指定时,请在didReceiveRemoteNotification中选中它