我一直在(成功地)使用 Google Firebase Messaging 系统。我可以向我的 iPhone 发送消息并订阅/取消订阅群组/主题,现在我想在推送通知到达手机时对其进行管理和处理。
// Receive displayed notifications for iOS 10 devices.
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo
// Print message ID.
if let messageID = userInfo[gcmMessageIDKey] {
print("1 Message ID: \(messageID)")
}
// Print full message.
print(userInfo)
// Change this to your preferred presentation option
completionHandler([])
}
Run Code Online (Sandbox Code Playgroud)
这是来自谷歌的默认代码,当推送通知到达应用程序看到并打印时,它工作正常:
1 Message ID: 0:1007%4xxxxxxxxxa
[AnyHashable("gcm.message_id"): 0:1007%4xxxxxa, AnyHashable("aps"): {
alert = {
body = "Breaking News: "; …Run Code Online (Sandbox Code Playgroud)