我正在尝试使用一些自定义数据将有效负载通知从 php 发送到 ios,当应用程序在后台并收到通知时,然后在该通知上的选项卡上应用程序已打开但它没有调用 didReceiveRemoteNotification强>功能。它只有在 JSON 有 data 而没有 notification 参数时才有效。
从 PHP 发送到 firebasr API 的 JSON
{
"to":"[Token]",
"priority":"high",
"content_available":true,
"notification":{
"title":"TITLE",
"body":"Body",
"sound":"default",
"badge":"1"
},"data":{
"type":"link",
"image":"",
"link":"",
"itemId":"",
"categoryId":"",
"groupId":""
}
}
ios 代码
func application(application: UIApplication, didReceiveRemoteNotification userInfo:[NSObject : AnyObject],
fetchCompletionHandler completionHandler:
(UIBackgroundFetchResult) -> Void){
print("vvvvvvvvvvvvv=%@", userInfo)
}
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
if #available(iOS 8.0, *) {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
} else {
let types: UIRemoteNotificationType = [.Alert, .Badge, .Sound]
application.registerForRemoteNotificationTypes(types)
}
FIRApp.configure()
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.tokenRefreshNotification),name:kFIRInstanceIDTokenRefreshNotification, object: nil)
}
func applicationDidBecomeActive(application: UIApplication) {
connectToFcm()
}
func applicationDidEnterBackground(application: UIApplication) {
FIRMessaging.messaging().disconnect()
print("Disconnected from FCM.")
}
最佳答案
经过大量测试后,我发现“可用内容”应该在通知中并且应该像这样“可用内容”,问题是 firebase 以某种方式重新构建 JSON 以使其可读ios 所以你需要检查他们在每次测试中如何向你发送数据。
{
"to":"[Token]",
"priority":"high",
"notification":{
"title":"TITLE",
"body":"Body",
"sound":"default",
"badge":"1",
"content-available":true,
},"data":{
"type":"link",
"image":"",
"link":"",
"itemId":"",
"categoryId":"",
"groupId":""
}
}
关于php - 当应用程序在后台时,Firebase 通知数据不回调 didReceiveRemoteNotification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39182544/