哪个函数在 iOS 中接收来自 Firebase Messaging 的推送通知?
What function receives push notifications in iOS from Firebase Messaging?
一天前,我用来测试推送通知的 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,如果有人能帮我弄明白,我将不胜感激!
我有类似的东西,
这是我的回答 - Firebase Push Notifs Problem
这可能是问题所在,
我关闭了推送并从苹果开发中心删除了证书并重新创建了它们,这使一切正常工作。
"我也将这行代码设置为,
FIRInstanceID.instanceID().setAPNSToken(deviceToken as Data, type: FIRInstanceIDAPNSTokenType.sandbox)
推送到应用商店的时候我会改成.prod
。"
一天前,我用来测试推送通知的 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,如果有人能帮我弄明白,我将不胜感激!
我有类似的东西,
这是我的回答 - Firebase Push Notifs Problem
这可能是问题所在,
我关闭了推送并从苹果开发中心删除了证书并重新创建了它们,这使一切正常工作。
"我也将这行代码设置为,
FIRInstanceID.instanceID().setAPNSToken(deviceToken as Data, type: FIRInstanceIDAPNSTokenType.sandbox)
推送到应用商店的时候我会改成.prod
。"