Quickstart-ios: No notifications in background on iOS 10 (Swift)

Created on 20 Sep 2016  ·  7Comments  ·  Source: firebase/quickstart-ios

I've implemented everything according to the guides and this example: https://github.com/firebase/quickstart-ios/blob/master/messaging/FCMSwift/AppDelegate.swift

I do receive messages when my app is in the foreground, but I don't when it's in the background.

When I remove the iOS 10 specific code like this …

    //if #available(iOS 10.0, *) {
    //  let authOptions : UNAuthorizationOptions = [.Alert, .Badge, .Sound]
    //  UNUserNotificationCenter.currentNotificationCenter().requestAuthorizationWithOptions(
    //    authOptions,
    //    completionHandler: {_,_ in })
    //
    //  // For iOS 10 display notification (sent via APNS)
    //  UNUserNotificationCenter.currentNotificationCenter().delegate = self
    //  // For iOS 10 data message (sent via FCM)
    //  FIRMessaging.messaging().remoteMessageDelegate = self
    //
    //} else {
      let settings: UIUserNotificationSettings =
      UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
      application.registerUserNotificationSettings(settings)
      application.registerForRemoteNotifications()
    //}

… everything works as expected.
Please advice. All help is greatly appreciated.

Most helpful comment

https://github.com/firebase/quickstart-ios/pull/101

I struggled with this for days, then compared to the Objective-C sample that worked properly. The iOS 10 version is missing the registerForRemoteNotifications() function call. The pull request above should fix it.

All 7 comments

I don't receive any messages in foreground, just background. :(

https://github.com/firebase/quickstart-ios/pull/101

I struggled with this for days, then compared to the Objective-C sample that worked properly. The iOS 10 version is missing the registerForRemoteNotifications() function call. The pull request above should fix it.

Thank you @roughike, you've saved me at least three gray hairs.
Is there any way I can upvote your pull request?

@pimnijman Glad I helped!

Maybe add a 👍 reaction to the PR and/or a comment saying that it fixed the problem for you as well.

I followed this guide and it worked.

@sir-gon Yeah, with Objective-C there's no problem. Try the Swift sample and you know what we're talking about.

@pimnijman Maybe change the title to say this happens with the Swift sample to avoid confusion and be more specific?

I'm having a similar issue, but with my app I'm migrating from Swift to Objective C (React Native). Pushes work on fresh install for Obj C but after migrating from Swift to Obj C, no pushes come through. I get all the tokens (APNS and FB) though and use the fcm console to send the push.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mrithula-quintet picture mrithula-quintet  ·  3Comments

isipisi281 picture isipisi281  ·  9Comments

kamrankhan07 picture kamrankhan07  ·  7Comments

zsajjad picture zsajjad  ·  8Comments

abdulKarim002 picture abdulKarim002  ·  6Comments