Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No notifications in background on iOS 10 (Swift) #103

Closed
pimnijman opened this issue Sep 20, 2016 · 7 comments
Closed

No notifications in background on iOS 10 (Swift) #103

pimnijman opened this issue Sep 20, 2016 · 7 comments

Comments

@pimnijman
Copy link

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.

@lethianqt94
Copy link

lethianqt94 commented Sep 20, 2016

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

@roughike
Copy link
Contributor

#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.

@pimnijman
Copy link
Author

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

@roughike
Copy link
Contributor

roughike commented Sep 21, 2016

@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.

@sir-gon
Copy link

sir-gon commented Sep 23, 2016

I followed this guide and it worked.

@roughike
Copy link
Contributor

@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?

@pimnijman pimnijman changed the title No notifications in background on iOS 10 No notifications in background on iOS 10 (Swift) Sep 26, 2016
@evanjmg
Copy link

evanjmg commented Apr 7, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants