【问题标题】:What function receives push notifications in iOS from Firebase Messaging?什么功能在 iOS 中从 Firebase 消息接收推送通知?
【发布时间】: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


    【解决方案1】:

    我也有类似的,

    这是我的答案 - Firebase Push Notifs Problem

    这可能是问题所在,

    我关闭了推送并从苹果开发中心删除了证书并重新创建它们,这使得一切正常运行。

    "我也将这行代码设置为,

    FIRInstanceID.instanceID().setAPNSToken(deviceToken as Data, type: FIRInstanceIDAPNSTokenType.sandbox)
    

    我会在推送到应用商店时将其更改为.prod。”

    【讨论】:

    • 谢谢,我会试试看。在您添加的行上方有一条注释为// With swizzling disabled you must set the APNs token here.。那你关掉swizzling了吗?
    • 我将不得不检查。我会试着在一天结束时看看。
    猜你喜欢
    • 2019-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-05
    • 1970-01-01
    • 2019-04-23
    • 2021-11-20
    相关资源
    最近更新 更多