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

FCM Push notifications do not work on iOS 11 #327

Closed
alexanderkhitev opened this issue Sep 24, 2017 · 64 comments
Closed

FCM Push notifications do not work on iOS 11 #327

alexanderkhitev opened this issue Sep 24, 2017 · 64 comments

Comments

@alexanderkhitev
Copy link

alexanderkhitev commented Sep 24, 2017

I use Firebase as a backend. I also use FCM as one of the provided features from Firebase. FCM worked well in iOS 10, but after switching to iOS 11, push notifications stopped coming to user devices, and I myself did not receive any push notifications sent from the cloud functions or the Notification section in the Firebase Console. How to fix this problem?

Update: I sent several push notifications from Firebase Notifcations, but they do not come.

// MARK: - Push notification

extension AppDelegate: UNUserNotificationCenterDelegate {
    
    func registerPushNotification(_ application: UIApplication) {
        // For iOS 10 display notification (sent via APNS)
        UNUserNotificationCenter.current().delegate = self
        
        let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
        UNUserNotificationCenter.current().requestAuthorization(
            options: authOptions,
            completionHandler: {_, _ in })
                
        // For iOS 10 data message (sent via FCM)
        Messaging.messaging().delegate = self
    }
    
    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        //When the notifications of this code worked well, there was not yet.
        Messaging.messaging().apnsToken = deviceToken
    }
    
    // [START receive_message]
    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
        // If you are receiving a notification message while your app is in the background,
        // this callback will not be fired till the user taps on the notification launching the application.
        // TODO: Handle data of notification
        // Print message ID.
        if let messageID = userInfo[gcmMessageIDKey] {
            debugPrint("Message ID: \(messageID)")
        }
        
        // Print full message.
        debugPrint(userInfo)
    }
    
    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
                     fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        // If you are receiving a notification message while your app is in the background,
        // this callback will not be fired till the user taps on the notification launching the application.
        // TODO: Handle data of notification
        // Print message ID.
        if let messageID = userInfo[gcmMessageIDKey] {
            print("Message ID: \(messageID)")
        }
        
        // Print full message.
        debugPrint(userInfo)
        
        completionHandler(.newData)
    }
    
    // showing push notification
    
    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
        if let userInfo = response.notification.request.content.userInfo as? [String : Any] {
            let routerManager = RouterManager()
            routerManager.launchRouting(userInfo)
        }
        completionHandler()
    }
    
    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        if let userInfo = notification.request.content.userInfo as? [String : Any] {
            if let categoryID = userInfo["categoryID"] as? String {
                if categoryID == RouterManager.Categories.newMessage.id {
                    if let currentConversation = ChatGeneralManager.shared.currentChatPersonalConversation, let dataID = userInfo["dataID"] as? String  {
                        // dataID is conversationd id for newMessage
                        if currentConversation.id == dataID {
                            completionHandler([])
                            return
                        }
                    }
                }
            }
            if let badge = notification.request.content.badge {
                AppBadgesManager.shared.pushNotificationHandler(userInfo, pushNotificationBadgeNumber: badge.intValue)
            }
        }
        completionHandler([.alert,.sound, .badge])
    }
    
}

// [START ios_10_data_message_handling]
extension AppDelegate : MessagingDelegate {
    
    func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) {
        let pushNotificationManager = PushNotificationManager()
        pushNotificationManager.saveNotificationTokenInDatabase(token: fcmToken, success: nil, fail: nil)
    }

    
    // Receive data message on iOS 10 devices while app is in the foreground.
    func application(received remoteMessage: MessagingRemoteMessage) {
        debugPrint(remoteMessage.appData)
    }
    
}
@ryanwilson ryanwilson assigned ryanwilson and rsattar and unassigned ryanwilson Sep 25, 2017
@caiovidaln
Copy link

I have the same problem.

@alexanderkhitev
Copy link
Author

Hi @caiovidaln !
Please see my answer on my question https://stackoverflow.com/questions/46391818/fcm-push-notifications-do-not-work-on-ios-11 It helped me, I'm currently testing, so that everything works as before, but unfortunately it will be necessary to wait until Apple confirms the new Build.

@berlininsomniac
Copy link

We have the same issue. Once the app goes into the background, no pushes are received at all.

@visskiss
Copy link

visskiss commented Sep 27, 2017

Also not receiving push notifications with iOS 11 and latest firebaseMessaging 2.0.3, firebase 4.2.0. I have used the apps.sh script to test and i receive those notifications, but using the fcm id and sending through the console and I receive nothing.

I just did a drop in replace from previous version 1.2.1 and 3.11.1 (had to add one delegate function for token update).

@ordinaryman09
Copy link

I noticed from your code, you're not running the request for push authorization from application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions, perhaps you call it at later time?

I have similar issue. I updated to Firebase 4.2.0 and FirebaseMessaging 2.0.3, my issue is I'm not getting notification if I do request push notification at later time. (I'm doing soft request/custom dialog to check if user want to receive push notification, before using the system request). I was able to reproduce it from the quickstart project by adding a delay to the requestAuthorization for push. Here's my SO thread: https://stackoverflow.com/questions/46443189/firebase-messaging-not-sending-notification-when-push-notification-authenticatio

@rsattar
Copy link
Contributor

rsattar commented Sep 27, 2017

There is a known issue where the FCM token is not always being associated with the APNs device token if UIApplication.shared.registerForRemoteNotifications() is not called early enough. This has already been fixed in the FirebaseInstanceID SDK, and should be coming out soon.

In the meantime, you can:

  1. Lock your FirebaseInstanceID pod to 2.0.0 in your Podfile, or

  2. Ensure you're calling UIApplication.shared.registerForRemoteNotifications() on app start, ideally before FirebaseApp.configure().

For testing, you can trigger a new FCM token by uninstall/reinstall your debug app on your device.

@ordinaryman09
Copy link

Got it. do you have any ETA when the version will be released?
Tried to lock it, setting pod 'FirebaseInstanceID', '~> 2.0.0' , but it kept using the 2.0.3, How do I downgrade it?

@jetboh
Copy link

jetboh commented Sep 27, 2017

@rsattar Thanks so much! Locking FirebaseInstanceID to 2.0.0 worked for me.
@ordinaryman09 remove the arrow for an exact match: pod 'FirebaseInstanceID', '2.0.0'

@morganchen12
Copy link
Contributor

@ordinaryman09 to specify exact versions, you should use '= 2.0.0'. CocoaPods' ~> specifier will use the most recent compatible version.

@vazkir
Copy link

vazkir commented Sep 28, 2017

Both downgrading the FirebaseInstanceID and FirebaseMessaging and placing the UIApplication.shared.registerForRemoteNotifications() as the first thing in the didFinishLaunchingWithOptions still doesn't work and gives a similar error. Is there anything else I can do?

@rsattar
Copy link
Contributor

rsattar commented Sep 28, 2017

@10686142 try uninstalling the app and reinstalling with the code changes, to ensure that a new FCM token gets issued

@vazkir
Copy link

vazkir commented Sep 28, 2017

Yeah somehow I still can't get it to work, but maybe I did something wrong since I am new to this. But maybe someone knows what it can be:
I followed this tutorial: https://www.youtube.com/watch?v=_jy_Hlskmiw&t=710s
Which came down to me delegate looking like this: https://github.com/douglasdevelops/PushNotificationSample/blob/master/PushNotificationSample/AppDelegate.swift

Is he maybe missing something is his explanation or am I missing something?

Thanks in advance!

@richardliveraise
Copy link

Thanks @jtbh89 & @rsattar , I downgraded to 2.0.0 and it works for me now. @10686142 what messages are you seeing? Do you get the tokens?

@vazkir
Copy link

vazkir commented Sep 28, 2017

2017-09-28 21:26:20.067218+0200 App Imperium News[1026:80671] [Firebase/Messaging][I-FCM002019] FIRMessaging received data-message, but FIRMessagingDelegate's-messaging:didReceiveMessage: not implemented
2017-09-28 21:27:05.337971+0200 App Imperium News[1026:80673] TIC Read Status [5:0x0]: 1:57
2017-09-28 21:27:05.338807+0200 App Imperium News[1026:80673] TIC Read Status [5:0x0]: 1:57

@vazkir
Copy link

vazkir commented Sep 28, 2017

Yeah I did also receive the token. And I got it to work earlier today that I could also see the push notification message in my debug log, but I always get that message about FIRMessagingDelegate's-messaging:didReceiveMessage: not implemented

@vazkir
Copy link

vazkir commented Sep 28, 2017

I got it to work finally guys! I added this piece of code:
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken
}

@vazkir
Copy link

vazkir commented Sep 28, 2017

Beginners mistake I think, thanks for your help! @rsattar @richardliveraise

@ordinaryman09
Copy link

it works for me after downgrading to 2.0.0, thanks guys!

@driverslicense
Copy link

@rsattar Without using CocoaPods, how is it possible to downgrade to 2.0.0 to fix this? Can you provide a link to download the working framework(s)?

@morganchen12
Copy link
Contributor

@Candywriter you can download the tar.gz from the link in the 2.0.0 podspec without using CocoaPods.

https://dl.google.com/dl/cpdc/9fe91bfb8772be4b/FirebaseInstanceID-2.0.0.tar.gz

@driverslicense
Copy link

@morganchen12 Thanks! Unfortunately manually replacing FirebaseInstanceID 2.0.3 with 2.0.0 produces a host of build errors.

@visskiss
Copy link

I had no issues. Are you on the latest download besides that?

@phr85
Copy link

phr85 commented Sep 29, 2017

Try to set this, works for me:

Messaging.messaging().shouldEstablishDirectChannel = true

@phr85
Copy link

phr85 commented Sep 29, 2017

Sorry, my memories solution isn't really the solution. Message just arrived when app is active.

@farazq
Copy link

farazq commented Sep 29, 2017

Downgrading FirebaseInstanceID to 2.0.0 did not work for me either.
However, adding this did work:
Messaging.messaging().apnsToken = deviceToken
in didRegisterForRemoteNotificationsWithDeviceToken

I'm confused why it works because this is only supposed to be in place if you have swizzling disabled, which I don't.

@keitaoouchi
Copy link

In iOS11.0, there seems to be a problem with iOS itself in handling silent push notification.
https://stackoverflow.com/questions/44796613/silent-pushes-not-delivered-to-the-app-on-ios-11

@o15a3d4l11s2
Copy link

@keitaoouchi I don't believe this is the reason for not receiving the notifications. They say this issue mentioned in StackOverflow is already fixed. Even if it is not - I experience a different issue - I always receive the push notifications when targeting a single device and very rarely receive notifications when sending to a User Segment.

@shintegu
Copy link

shintegu commented Oct 6, 2017

I'm also encountering the issue of @o15a3d4l11s2. I can receive push notifications by sending message to a single device, but almost nothing when using User Segment.

@eduardoParadoja
Copy link

I wasn't receiving any notifications until I deleted the .p12 files from the firebase console and upload the .p8 file https://stackoverflow.com/questions/39672297/how-to-use-apples-new-p8-certificate-for-apns-in-firebase-console

@o15a3d4l11s2
Copy link

o15a3d4l11s2 commented Oct 6, 2017

@eduardoParadoja Thanks for the suggestion. I use APN Auth Key and not APN Push Certificate.

@jacobmoncur
Copy link

I am seeing the exact same issue as @o15a3d4l11s2.

We are using the console (https://console.firebase.google.com) to send notifications. If I target an individual device using the FCM token the notification is received. If I try to send to a User Segment the notification is not received. 🤷

  • We have the latests versions of the SDK installed. (Firebase 4.3.0 , FirebaseAnalytics 4.0.4, FirebaseCore 4.0.8, FirebaseInstanceID 2.0.4, FirebaseMessaging 2.0.4)
  • We are using the APN Auth Key .p8
  • We are calling UIApplication.shared.registerForRemoteNotifications() on app start in didFinishLaunchingWithOptions and before FirebaseApp.configure()

@amervil
Copy link

amervil commented Oct 7, 2017

Exact the same issue as @jacobmoncur. Even same versions of Firebase, .p8, Xcode 9

@vincentsong
Copy link

Same issue as @jacobmoncur's. We need to ask user give permission to push notification after FirebaseApp configuration.

@ericklarac
Copy link

How do I use this solution? fix is pod 'FirebaseInstanceID', "2.0.0"

HELP, PLEASE.

@ordinaryman09
Copy link

@ericklarac You add it on your Podfile

@johnnyrockenstein
Copy link

Pods:
pod 'Firebase/Core', '4.0.4'
pod 'Firebase/Database', '4.0.4'
pod 'Firebase/Messaging', '4.0.4'
pod 'FirebaseInstanceID', '2.0.0'

Getting
2017-10-11 00:45:28.181 Customer Connect[1964] [Firebase/Messaging][I-FCM002019] FIRMessaging received data-message, but FIRMessagingDelegate's-messaging:didReceiveMessage: not implemented

Any suggestions?

@lsalvoni
Copy link

@dhorrock You need to subscribe to the FIRMessagingDelegate and add the missing delegate method; see sample code in the AppDelegate.m of the MessagingExample project for your language of choice.

@raghuyt
Copy link

raghuyt commented Oct 11, 2017

Hi all am also facing same problem ,but am not installed plugin coco pod on ios ,installed only "cordova-plugin-fcm" and done FCM setting its working all IOS Expect 11. am able to get token id also, sending notification through API getting successful responses also ,but notification not coming IOS 11 but 10 its coming

Any suggestions?

@kerimsari
Copy link

Can not get it to work either same problem with @o15a3d4l11s2.

@ericklarac
Copy link

@kerimsari @raghuyt @dhorrock
What I did was:

  1. I opened terminal on the folder of the project, deleted the Podfile.lock.

  2. Then exec pod install, with the following pods on Podfile:

    • pod 'Firebase/Core'
    • pod 'Firebase/Messaging'
    • pod 'FirebaseInstanceID', "2.0.0"
  3. Then I reviewed the certificates.

  4. Run the project.

Note: If you are facing problems and you don't find a solution, I recommend you to start a new project and review each step. You can use the quickstart-ios example of firebase or this example which I found it awesome.

@raghuyt
Copy link

raghuyt commented Oct 12, 2017

Hi @ericklarac

How can i install this for cordova apps

pod 'Firebase/Core'
pod 'Firebase/Messaging'
pod 'FirebaseInstanceID', "2.0.0"

Please can you help me with this .

@kerimsari
Copy link

Hi @ericklarac

I've done what you said and i can send notifications via topic target but not to user segment..

Please suggest

@ericklarac
Copy link

@raghuyt Open up Terminal on the folder of the project then edit the Podfile, you can use nano or vi and just paste those lines (i.e. mine looks like this):

image

Then you save it and run the command: pod install, open the .xcworkspace with Xcode, run the project and you are done.

@kerimsari If the notifications status on the firebase consoles is completed, click the notification and look the chart if sent is 0 it's because firebase isn't storing the tokens. Actually, I don't know how user segment works on the firebase console at all, but hope I could work.

@raghuyt
Copy link

raghuyt commented Oct 13, 2017

@ericklarac thank you now its working in all IOS versions ,till now IOS version 11.0.2 its working all devices
what i made changes is this
updated our cordova to new version and platform IOS to new version

@Dragna
Copy link

Dragna commented Oct 19, 2017

I had the same problem on my phone and solved it by restarting the phone, I was receiving the push after that. I hope it Will be the same for you.

@ordinaryman09
Copy link

Firebase released a new update, anybody tested the new one?

@shihochan
Copy link

I have a problem don't receive push notification on my some devices.

Environment:

  • Xcode9
  • Swift4

Devices:
iPhone6S Plus (9.3.2)
iPhone5S (10.3.2)
iPad Pro (10.2.1)
iPhone7 Plus (10.2.1)

In my Podfile.lock:

  - Firebase/Core (4.3.0):
  - Firebase/Messaging (4.3.0):
    - FirebaseMessaging (= 2.0.4)
  - FirebaseInstanceID (2.0.4)

Did v4.0.4~ really fix push problem??

@ericklarac
Copy link

Are you uploading the apple certificates (.p12 files) to firebase?

@kroikie
Copy link
Contributor

kroikie commented Oct 20, 2017

@shihochan It may be useful to create a new issue since this one is closed. There are different ways in which messages should be handled between iOS 9 and 10 so that could be an issue but a new issue with more detail of your setup and how you are sending the message would be helpful.

@charlotteliang
Copy link
Contributor

Agree with @kroikie Looks like this thread has been involved with many off-topic issues. If your issue is different than what's on the title (that's been closed), please file a new issue and we will look into each individual one. Thanks!

@morganchen12 morganchen12 reopened this Oct 20, 2017
@firebase firebase locked and limited conversation to collaborators Oct 20, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests