我正在我的应用程序中集成firebase推送通知。在最新版本的iOS中它工作正常。但在低版本的iOS中我遇到了一些问题。
在低版本的iOS中,didReceiveRemoteNotification回调会在没有用户点击通知的情况下自动触发。
在低版本iOS中自动调用,无需用户点击通知
[AnyHashable("notification"): {
body = “body text”;
e = 1;
sound = default;
sound2 = default;
title = “title here”;
}, AnyHashable("from”):2343434, AnyHashable("a_data"): ****, AnyHashable("collapse_key"): com.***.****]
用户选中通知
后的最新iOS版本[AnyHashable("a_data"):****, AnyHashable("aps"): {
alert = {
body = "body";
title = "title";
};
sound = default;
}, AnyHashable("gcm.message_id"): ******]
这是我的代码
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
// If you are receiving a notification message while your app is in the background,
// this callback will not be fired till the user taps on the notification launching the application.
// Print full message.
print("user t \(userInfo)")
completionHandler(UIBackgroundFetchResult.newData)
print(userInfo)
let aps = userInfo["aps"] as! [String: AnyObject]
let alert = aps["alert"] as! [String: AnyObject]
let eventTitle : String = alert["title"] as! String? ?? "Title"
print(alert["title"] ?? "Title")
}
// This method will be called when app received push notifications in foreground
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
{
completionHandler([.alert, .badge, .sound])
}
希望你理解我的问题。 如何解决这个问题呢? 提前致谢