【问题标题】:Push notification from Firebase not received in iOS 13 and above versionsiOS 13 及更高版本未收到来自 Firebase 的推送通知
【发布时间】:2019-11-05 11:44:14
【问题描述】:

在应用中未收到来自 Firebase 的推送通知。 吊舱详细信息: 这些是我使用的依赖项:

Firebase (6.10.0)

FirebaseAnalytics (6.1.3)

FirebaseAnalyticsInterop (1.4.0)

FirebaseAuth (6.3.0)

FirebaseAuthInterop (1.0.0)

FirebaseCore (6.3.1)

FirebaseCoreDiagnostics (1.1.1)

FirebaseCoreDiagnosticsInterop (1.0.0)

Firebase 数据库 (6.1.1)

FirebaseInstanceID (4.2.5)

FirebaseMessaging (4.1.6)

iOS 12 及以下版本收到 swift 5.1 的推送通知。但是 iOS 13 没有收到任何推送通知。云端发送推送成功消息。

func authForRemoteNotificationsIn(_ application: UIApplication) {

    // Verify the remote notification registration status
    guard !application.isRegisteredForRemoteNotifications || UserDefaults.fcmToken.isEmpty else { return }

    /**
     Specify the notification options
     * Disbled sound: Silent notifications are more helpful the user
     */
    let authOptions: UNAuthorizationOptions = [.badge]
    // Requset the authorization
    UNUserNotificationCenter.current().requestAuthorization(options: authOptions) { (_, error) in

        // Validate the request status
        guard let error = error else { return }
        print(error.localizedDescription)
    }

    // Request device token
    application.registerForRemoteNotifications()
}


func application(_ application: UIApplication,    didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    print(#function)

    Messaging.messaging().delegate = self
    Messaging.messaging().isAutoInitEnabled = true
    Messaging.messaging().apnsToken = deviceToken
}

【问题讨论】:

    标签: ios firebase


    【解决方案1】:

    您能检查一下您是如何接收设备令牌的吗?它针对 iOS 13 进行了更改,因此您在 API 上注册的格式可能不受支持。

    查看this approach.

    【讨论】:

    • 我不需要保存令牌。我只想使用以下代码将其发送到 firebase:Messaging.messaging().apnsToken = deviceToken
    • 没错,我的意思是这个 deviceToken 被分配给 Messaging.messaging().apnsToken。我的问题是这个令牌的格式是否适合 Firebase。
    • 是的。测试了 12 版本(推送通知成功)和 13 版本(推送通知失败)。两个设备令牌都是 32 字节。
    猜你喜欢
    • 2018-06-21
    • 2019-04-19
    • 1970-01-01
    • 2017-01-24
    • 2016-07-22
    • 2016-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多