1

我已經創建了具有通知的應用程序。當我在開發者模式上發送通知時,我收到通知。但是當我發佈發佈mod我什麼都沒有得到。我讀到我應該將證書更改爲產品證書。但它沒有幫助。這裏是我的appdelegate:未在Testflight上工作的Firebase通知

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.") 
} 
+1

你設置了'kGGLInstanceIDAPNSServerTypeSandboxOption:@NO};'?就像這裏所做的一樣:http://stackoverflow.com/q/37628158/4625829? –

+0

不,我想。 :/我會嘗試並儘快回覆。 – MRustamzade

+0

沒有工作。 :/我使用fcm不是gcm。 – MRustamzade

回答

1

通過這個剛走到,

我轉身蹬,並刪除了蘋果開發中心的證書,並創造了他們一遍,這使一切工作,因爲它應該。

我也有這行設置爲代碼,

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

,當我推到了應用商店,我將其更改爲.prod

0

我找到了解決辦法。問題在於產品證書。我忘了添加產品到firebase。