【发布时间】:2017-03-31 06:14:06
【问题描述】:
一天前我用来测试推送通知的 iPhone 收到了推送通知,但由于某种原因,今天却没有。
当它工作时,我会调用完成处理程序以在此函数中显示通知:
@available(iOS 10, *)
extension AppDelegate : UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
completionHandler([.alert, .badge, .sound])
}
但是,该函数似乎不再被调用。我看到打印的唯一功能是这个:
extension AppDelegate : FIRMessagingDelegate {
// Receive data message on iOS 10 devices while app is in the foreground.
func applicationReceivedRemoteMessage(_ remoteMessage: FIRMessagingRemoteMessage) {
print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
print(remoteMessage.appData)
}
}
我从Firebase Send a Notification to an iOS Device docs 获得了所有这些功能。我真正想要的只是能够从 Apple 的 APNs 服务器接收推送通知。我在我的控制台APNs token retrieved: 32 bytes 中收到了这条线,而且推送通知昨天还在工作,所以我不确定它为什么停止了。
我怀疑它停止工作的唯一原因是我删除了该应用程序并将其重新安装到 iPhone 上,除了我根本没有弄乱AppDelegate 中的代码。谁能帮我弄清楚为什么我的推送通知可能已停止发送?
注意我正在使用 Firebase Messaging topics 从我的云功能发送这些消息,我可以确认在上面的第二个函数中接收消息时正确发送消息,而不是在第一个函数中就像昨天收到的一样。我正在使用admin.messaging().sendToTopic(pet_Id, payload, options); 发送通知。
这是我的full AppDelegate.swift file,如果有人能帮我弄清楚,我将不胜感激!
【问题讨论】:
标签: ios swift firebase apple-push-notifications firebase-cloud-messaging