Firebase 通知不适用于 Testflight

Firebase Notification not working on Testflight

我已经创建了带有通知的应用程序。当我向开发人员 mode 发送通知时,我会收到通知。但是当我发送发布 mod 时,我什么也没收到。我读到我应该将证书更改为产品证书。但这没有帮助。这是我的 appdelegate:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.


    FIRApp.configure()

    let notificationTypes : UIUserNotificationType = [.alert, .badge, .sound]
    let notificationSettings : UIUserNotificationSettings = UIUserNotificationSettings(types: notificationTypes, categories: nil)
    application.registerForRemoteNotifications()
    application.registerUserNotificationSettings(notificationSettings)

    return true
}

private func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
    FIRMessaging.messaging().subscribe(toTopic: "/topics/main")
}

private func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData)
{
    FIRInstanceID.instanceID().setAPNSToken(deviceToken as Data, type: FIRInstanceIDAPNSTokenType.prod)
}

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    print(userInfo["gcm.message_id"]!)
    print(userInfo)
}

func application(_ application: UIApplication, dirtings: UIUserNotificationSettings)
{
    UIApplication.shared.registerForRemoteNotifications()
}

func tokenRefreshNotification(notification: NSNotification) {
    if let refreshedToken = FIRInstanceID.instanceID().token() {
        print("InstanceID token: \(refreshedToken)")
    }

    // Connect to FCM since connection may have failed when attempted before having a token.
    connectToFcm()
}



func connectToFcm() {
    FIRMessaging.messaging().connect { (error) in
        if (error != nil) {
            print("Unable to connect with FCM. \(error)")
        } else {
            print("Connected to FCM.")
        }
    }
}

private func applicationDidEnterBackground(application: UIApplication) {
    FIRMessaging.messaging().disconnect()
    print("Disconnected from FCM.")
}

刚经历过这个,

我关闭了推送并从苹果开发中心删除了证书并重新创建了它们,这使得一切都按预期工作。

我也将这行代码设置为,

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

我推送到应用商店的时候会改成.prod

我找到了解决方案。问题出在产品证书上。我忘了将 prod 证书添加到 firebase。