2

I have created app with notification. When i send notification on developer mode then i get notifications. but when i send on release mod i don't get anything. I read that i should change certificate to product certificat. But it doesn't helped. here is my 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.")
}
AL.
  • 36,815
  • 10
  • 142
  • 281
MRustamzade
  • 1,425
  • 14
  • 27
  • 1
    Have you set the `kGGLInstanceIDAPNSServerTypeSandboxOption:@NO};`? Like what was done here: http://stackoverflow.com/q/37628158/4625829? – AL. Sep 17 '16 at 23:55
  • no i think. :/ i will try it and reply back as soon as i possible. – MRustamzade Sep 18 '16 at 02:17
  • not worked. :/ i'm using fcm not gcm. – MRustamzade Sep 18 '16 at 20:42
  • It's hard to pinpoint the reason why you're not receiving the messages with the limited details. I suggest going through the [docs](https://firebase.google.com/docs/cloud-messaging/ios/client) again and double check. – AL. Sep 19 '16 at 03:07
  • Have you added a production APNs cert to the Firebase console? – Arthur Thompson Sep 19 '16 at 17:05
  • Yes of course. In developer mode it works. – MRustamzade Sep 19 '16 at 18:35
  • For anyone else who comes along, that it works "in developer mode" is not relevant to Arthur Thompson's question in a comment above. TestFlight requires a PRODUCTION certificate; see "When you are ready to release your application, you need to enable the app to use the Push Notification production environment: repeat these steps, but click Create Certificate under the Production SSL Certificate section instead of Development SSL Certificate." from [Google Firebase docs - Provisioning APNs certificates](https://firebase.google.com/docs/cloud-messaging/ios/certs). – ToolmakerSteve Feb 14 '17 at 23:28
  • @ToolmakerSteve yes. I wrote it down – MRustamzade Feb 15 '17 at 01:05
  • 1
    Thanks - I figured you had resolved it by now; I just wanted anyone else who read this series of comments to understand :) – ToolmakerSteve Feb 15 '17 at 01:08

2 Answers2

3

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.

Ro4ch
  • 850
  • 8
  • 21
0

I found solution. problem was with prod certificate. i forget to add prod cetificate to firebase.

MRustamzade
  • 1,425
  • 14
  • 27