我必须创建我的测试通知项目并在其中使用Firebase框架。 我有一个问题,我知道这一点,但我无法解决,我很困惑!!! 由于我从服务器向应用程序发送了通知,因此我的项目称为此方法:
func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
print("NOTY")
print("Received data message: \(remoteMessage.appData)")
print("Received Remote Message: 2\nCheck Out:\n")
}
此方法在后台不起作用!!! 现在,由于我从Firebase控制台向应用程序发送了通知,因此我的项目使用了以下方法:
public func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo
print("NOTY5")
debugPrint(userInfo)
if let page = userInfo["page"] as? String {
if page == "finish_tr" {
}else if page == "one_page" {
}else if page == "payment" {
}
}
completionHandler([.alert, .badge, .sound])
此方法向我显示通知并在后台:D
现在我的问题在这里!!!
为什么在第一状态didReceive remoteMessage
中必须调用,而在第二状态中userNotificationCenter必须要调用!!!
它可能取决于有效载荷???
从服务器发送时,我的有效载荷是:
{
"priority":"high",
"registration_ids":[
""
],
"data":{
"page":"all_tender",
"body":"test body",
"tr_id":null,
"timestamp":1535879143,
"title":"title test"
},
"aps":{
"page":"all_tender",
"body":"test body",
"tr_id":null,
"timestamp":1535879143,
"title":"test title"
}
}
现在当我完成两个状态时,获取以下日志:
我在第一状态下获得此打印件:
[AnyHashable("from"): 1078335662056, AnyHashable("page"): all_tender, AnyHashable("title"): test title, AnyHashable("timestamp"): 1535883883, AnyHashable("body"): test body]
但是我得到了第二种状态的打印(firebase测试通知):
[AnyHashable("dsf"): dsf, AnyHashable("google.c.a.c_l"): sadf, AnyHashable("google.c.a.e"): 1, AnyHashable("google.c.a.ts"): 1535884249, AnyHashable("google.c.a.udt"): 0, AnyHashable("gcm.n.e"): 1, AnyHashable("aps"): {
alert = {
body = aaaaaa;
title = bbbbb;
};
}, AnyHashable("google.c.a.c_id"): 8610540651637958517, AnyHashable("gcm.message_id"): 0:1535884249651346%024f9630024f9630]