ios - Firebase 通知在 Testflight 上不起作用

标签 ios swift firebase firebase-cloud-messaging firebase-notifications

我创建了带有通知的应用程序。当我在开发者模式下发送通知时,我会收到通知。但是当我发送发行版时我什么也没有得到。我读到我应该将证书更改为产品证书。但这没有帮助。这是我的应用程序代理:

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

关于ios - Firebase 通知在 Testflight 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39550615/

相关文章:

ios - 在 UIAlertView 中添加颜色选择器

iOS,应用程序商店的 url 方案既适用于指定开发人员的应用程序,也适用于他在 iOS 6 中更新的具体应用程序?

arrays - Swift 数组 var 问题

ios - 核心数据-[Decodable.Address initWithCoder :]: unrecognised selector sent to instance

java - 让 TaskCompletionSource 正常工作(Firestore 的 Android 任务)

ios - Xcode 错误 : 'FirebaseCore/FirebaseCore.h' file not found

ios - UIAlertView 改变 UITabbar item 选中的颜色

ios - 检测到不正确的 NSStringEncoding 值 0x0000。假设 NSASCIIStringEncoding

ios - 如何在 Swift 5 中断开 BLE 设备

reactjs - 如何将多个文档添加到 firebase 中的集合中?