我使用PubNub服务而不是PubNub Chat Engine在我的应用程序中设置了聊天模块。一切正常,直到推送通知出现。这个应用程序也有Android版本(不是由我建立)。我能够使用下面提到的payload1接收功能齐全的Apple推送通知。但它仅适用于通知方面的iOS设备,没有为通知添加GCM的Android设备通知。
所以我做了一些RND并找到了这个Link并使用了Paylo2提到了下面。使用此平台可获得通知。但现在在iOS Notification中有前台应用程序状态和后台应用程序状态。但是所有下面提到的方法都没有调用,现在唯一的方法就是在前台调用willPresent。我想知道为什么会这样。是有什么东西错误的有效载荷或标签或什么?请帮助我为此奋斗一周。提前致谢。
payload1 = [
"aps" : [
"alert" : [
"title" : self.loginUserProfile.firstName,
"body" : message],
"pn_exceptions" : [
tokenString
],
"content-available": 1,
"sound" : "marco_alert.aiff",
"publisher" : self.loginUserProfile.userId,
"date" : Date().dateString()]
] as [String : Any]
payload2 = [
"pn_apns":
[
"date": Date().dateString(),
"aps":
[
"sound": "marco_alert.aiff",
"alert":
[
"title": self.loginUserProfile.firstName,
"body": message
],
],
"pn_exceptions": [tokenString],
"publisher": self.loginUserProfile.userId,
"content-available": 0
],
"pn_gcm": [
"data": messageString
]] as [String : Any]
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void)
和
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any])
和
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void)```
@Ahsan我想确保我理解你描述的行为:当应用程序在后台时,通过上面的有效负载通过PubNub发送的通知在Android和iOS上运行。但是当iOS应用程序是前台时,通知只调用func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler:
@escaping (UNNotificationPresentationOptions) -> Void)
?
如果是这样,那就是Apple官方iOS文档中描述的Apple iOS推送通知行为。从历史上看,推送通知旨在用于活动使用的应用程序之外的操作,因此这种记录的方法是作为更新的机制提供的,以便在应用程序处于活动状态时与推送通知进行交互。
您可能还想查看UNNotificationPresentationOptions
as well for the available choices here.