iOS Firebase 推送通知未出现

标签 ios swift xcode apple-push-notifications entitlements

我已根据此演练设置了推送通知:https://www.appcoda.com/firebase-push-notifications/

但是当我从 Firebase 发送测试消息时,它没有显示。我遵循了所有步骤,我有有效的证书:

enter image description here

为推送通知设置配置文件:

enter image description here

在我的 App ID 下,它显示通知已启用:

enter image description here

我已将证书上传到 Firebase:

enter image description here

在我的 AppDelegate didFinishLaunchingWithOptions 中:

    if #available(iOS 10.0, *) {
        // For iOS 10 display notification (sent via APNS)
        UNUserNotificationCenter.current().delegate = self
        let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
        UNUserNotificationCenter.current().requestAuthorization(
            options: authOptions,
            completionHandler: {_, _ in })
        // For iOS 10 data message (sent via FCM
        FIRMessaging.messaging().remoteMessageDelegate = self
    } else {
        let settings: UIUserNotificationSettings =
            UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
        application.registerUserNotificationSettings(settings)
    }


    application.registerForRemoteNotifications()

连同 AppDelegate 中的 Firebase 回调方法:

func applicationReceivedRemoteMessage(_ remoteMessage: FIRMessagingRemoteMessage) {
    print(remoteMessage.appData)
}

显然我已经导入了:

import UserNotifications
import FirebaseInstanceID
import FirebaseMessaging

我不确定为什么推送通知不起作用,似乎一切都已到位。我做的唯一不寻常的事情是从目标 -> 代码签名中删除了权利,因为当我尝试运行该应用程序时它给我一个无效的权利错误。现在它已被删除,应用程序运行良好。关于那个单独的问题,我确实有一个悬而未决的问题,但现在我假设这不是我这里出现问题的原因。

只是为了确认一下,我不必在添加通知后重新下载 Google plist?在添加通知之前,我在我的项目中使用了 Firebase,所以我已经有了一个。

感谢您帮助通知正常工作!

最佳答案

尝试在您的 info.plist 中添加 FirebaseAppDelegateProxyEnabled 类型“Boolean”值“NO”

并可能在您的 AppDelegate 中将 Messaging.messaging().shouldEstablishDirectChannel 添加到 true

关于iOS Firebase 推送通知未出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44416272/

相关文章:

c# - 如何在 Monotouch 中获取 iOS 设备和版本

swift - 非强引用在 Playground 上不起作用

ios - 重新启动应用程序时导入 header 错误 Swift

ios - 如何在 xCode 上更改代码常量的图标文件?

ios - 找不到开发者磁盘镜像 -xcode beta 7.2

iphone - 升级到 SDK 4.1,无法再针对 iOS 4.0 进行构建

iphone - itunesconnect 在防火墙后使用应用程序加载器

ios - IPAD : How to play video in fullscreen without User Action

ios - 解析 PFUser.currentUser 返回 nil - Swift

json - Swift 4 Codable 解码数组用引号括起来