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。