Firebase通知无法在Testflight

时间:2016-09-17 18:58:39

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

我已经通过通知创建了应用。当我在开发者模式上发送通知时,我会收到通知。但是当我发送发布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.")
}

2 个答案:

答案 0 :(得分:1)

Just went through this,

I turned push off and deleted the certs from apple dev center and created them all over again and this made everything work as it should.

I also had this line of code set to,

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

I will change it to .prod when I push to the app store.

答案 1 :(得分:0)

我找到了解决方案。问题是产品证书。我忘了给火柱添加刺激。