2

I've set up push notifications according to this walkthrough: https://www.appcoda.com/firebase-push-notifications/

But when I send a test message from Firebase, it doesn't show up. I followed all the steps, I have valid certificates:

enter image description here

Provisioning Profile set up for push notifications:

enter image description here

Under my App ID it shows that notifications are enabled:

enter image description here

And I have the certificate uploaded to Firebase:

enter image description here

And in my AppDelegate didFinishLaunchingWithOptions:

    if #available(iOS 10.0, *) {
        // 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
        FIRMessaging.messaging().remoteMessageDelegate = self
    } else {
        let settings: UIUserNotificationSettings =
            UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
        application.registerUserNotificationSettings(settings)
    }


    application.registerForRemoteNotifications()

Along with the Firebase callback method in AppDelegate:

func applicationReceivedRemoteMessage(_ remoteMessage: FIRMessagingRemoteMessage) {
    print(remoteMessage.appData)
}

And obviously I have imported:

import UserNotifications
import FirebaseInstanceID
import FirebaseMessaging

I'm not sure why the push notifications are not working, it seems like everything is in place. The only thing out of the ordinary I did was remove the entitlements from Target -> Code Signing, as it was giving me an invalid entitlements error when I tried to run the app. Now that it's removed, the app is running fine. I do have an open question about that separate issue but for now I'll assume that's not the cause of my problems here.

And just to confirm, I don't have to re-download the Google plist after adding notifications? I was using Firebase in my project before adding notifications, so I already have one.

Thanks for any help getting the notifications working!

mfaani
  • 33,269
  • 19
  • 164
  • 293
KingTim
  • 1,281
  • 4
  • 21
  • 29
  • please remove the device from Xcode and try ur getting the push or not?. and some times in development mode did register with notification not calling. – Phani Sai Jun 07 '17 at 15:13
  • Do any of you know if it's required to re-download the Google-Info.plist file after adding FirebaseMessaging/notifications? I had Firebase in my app before I tried to add notifications so I have the original plist. – KingTim Jun 07 '17 at 15:21

2 Answers2

1

Try Adding FirebaseAppDelegateProxyEnabled type "Boolean" value "NO" in your info.plist

and maybe add Messaging.messaging().shouldEstablishDirectChannel to true in your AppDelegate

COLD ICE
  • 840
  • 1
  • 12
  • 31
0

Can you check in the capabilities tab if push notifications are enabled. Also, since Xcode 8 you need to add the entitlements file with aps-environment set. If you disable and enable the push notifications from capabilities you will get this file.

Jasveer Singh
  • 354
  • 3
  • 10
  • Please have a look at the documentation - https://developer.apple.com/library/content/documentation/Miscellaneous/Reference/EntitlementKeyReference/Chapters/EnablingLocalAndPushNotifications.html – Jasveer Singh Jun 07 '17 at 15:18
  • Your "Also, since Xcode 8 you need to add the entitlements file with aps-environment set." is misleading. That happens automatically if you set in the capabilities. – mfaani Jun 07 '17 at 15:19
  • Push notifications are enabled in capabilities. I switched it to "off", then back on again. Re-downloaded my provisioning profile, double clicked to install. Ran and now I'm getting an error "invalid entitlements" – KingTim Jun 07 '17 at 15:19
  • @Honey Prior to Xcode 8 entitlements file was not required. – Jasveer Singh Jun 07 '17 at 15:22
  • It seems to be working now, but I'm still not seeing the test notifications I'm sending out from Firebase – KingTim Jun 07 '17 at 15:23
  • @KingTim Can you check in you target's build settings. Code Signing Entitlements has correct file name. – Jasveer Singh Jun 07 '17 at 15:24
  • @KingTim for the invalid entitlements see [here](https://stackoverflow.com/questions/19581225/the-executable-gets-signed-with-invalid-entitlements-in-xcode). And just to be sure. Are you using the simulator or an actual device? Because your simulator isn't able to create a token for you. Only actual devices can do that for you – mfaani Jun 07 '17 at 15:24
  • @Honey I'm using my device – KingTim Jun 07 '17 at 15:26
  • @JasveerSingh the correct entitlements file name is there. It's giving me the invalid entitlements error again. – KingTim Jun 07 '17 at 15:26
  • Just FYI, when your app is in foreground you will not see any default notifications. So send the notification while app is in background mode or killed. – Jasveer Singh Jun 07 '17 at 15:28
  • @KingTim did you see the link I shared for invalid entitlements? Try to first solve that issue on that page. Once it's fixed come back here and try solving the issue of not receiving any notifications. – mfaani Jun 07 '17 at 15:36
  • @Honey, I looked and tried every solution there. I also have an open question about the same issue. I've toggled and untangled all the recommended capabilities, regenerated provisioning profiles, cleaned, restarted Xcode. No luck. – KingTim Jun 07 '17 at 15:40
  • @KingTim Then you should have not opened this question! Try to comment on the answers of your question and fix that issue first. I mean how do you expect it to work while you still have that issue?! You can place a bounty on it, but you can do it after 48hrs – mfaani Jun 07 '17 at 15:42
  • To be clear, the app runs if I simple delete the entitlements from Target -> Code Signing. Is removing the entitlements like that causing this issue with the push notifications not working? – KingTim Jun 07 '17 at 15:44
  • Don't remove the entitlements, try to fix the issue with entitlement. Push notifications will not work without it. – Jasveer Singh Jun 07 '17 at 15:46
  • I've tried every suggestion on every question on the topic I can find. If you know how to solve the entitlements issue, please don't be shy! https://stackoverflow.com/questions/44412788/invalid-entitlements-error-when-adding-push-notifications – KingTim Jun 07 '17 at 15:48