我正在使用Firebase推送通知iOS应用,但是在某些情况下,我们不必向用户显示推送通知,只有我必须使用随推送通知一起收到的数据。
从服务器发送的有效载荷:
{
to: iosTokenList[i],
notification: {
title: 'Hidden',
body: "Hidden",
Data: {
"Id":Id,
"someList":SomeList,
"status": "inactive"
},
notificationType: "status"
},
问题
当我不发送notification.title
和notification.body
时,则在ios应用中未收到推送通知。在appDelegate中没有方法被调用,
但是当我们添加notification.title=somevalue
和notification.body=somevalue
时,willPresent
被称为。
AppDelegate
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
NotificationParser.parseIncommingMessages(notification: notification)
completionHandler([.alert, .sound])
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
print("PushNotifications : \(userInfo)")
if #available(iOS 10.0, *){
}else{
let dict = userInfo as NSDictionary
if let alert = dict.value(forKeyPath: "aps.alert") as? String{
let alert = UIAlertController(title: appTitle , message: alert + "didReceiveRemoteNotification", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
appDel.window?.rootViewController?.present(alert, animated: true, completion: nil)
}
}
}