Firebase-ios-sdk: Push Notifications Not Working for Catalyst

Created on 9 Mar 2020  ·  35Comments  ·  Source: firebase/firebase-ios-sdk

I am unable to get push notifications working for Catalyst. My current setup works correctly for iOS but shows an authentication error for Catalyst.

Code Excerpts

      FirebaseApp.configure(options: options)
        Messaging.messaging().delegate = self
        UNUserNotificationCenter.current().delegate = self

      func registerForPushNotifications(completionHandler : @escaping () -> Void) {
        UNUserNotificationCenter.current().getNotificationSettings() { settings in
            guard settings.authorizationStatus == .authorized else { return }

            DispatchQueue.main.async {
                UIApplication.shared.registerForRemoteNotifications()
                iOSNotificationService.shared.getPendingNotifications()
                completionHandler()
            }
        }
    }


func requestPushNotificationAuthorization(completionHandler: @escaping ()-> Void ) {
        let authOptions : UNAuthorizationOptions = [.alert, .badge, .sound]
        UNUserNotificationCenter.current().requestAuthorization(options: authOptions) { (granted, error) in
            guard granted else {
                if let errorString = error?.localizedDescription {
                    os_log("Push notification authorization denied : %{public}s", errorString )
                }

                return
            }
            self.registerForPushNotifications() {
               // 
               //
            }

            completionHandler()
        }
    }

*Error *
{ Error: Auth error from APNS or Web Push Service Raw server response: "{"error":{"code":401,"message":"Auth error from APNS or Web Push Service","status":"UNAUTHENTICATED","details":[{"@type":"type.googleapis.com/google.firebase.fcm.v1.FcmError","errorCode":"THIRD_PARTY_AUTH_ERROR"}]}}"
at FirebaseMessagingError.FirebaseError [as constructor] (/srv/node_modules/firebase-admin/lib/utils/error.js:42:28)
at FirebaseMessagingError.PrefixedFirebaseError [as constructor] (/srv/node_modules/firebase-admin/lib/utils/error.js:88:28)
at new FirebaseMessagingError (/srv/node_modules/firebase-admin/lib/utils/error.js:253:16)
at Function.FirebaseMessagingError.fromServerError (/srv/node_modules/firebase-admin/lib/utils/error.js:283:16)
at Object.createFirebaseError (/srv/node_modules/firebase-admin/lib/messaging/messaging-errors.js:34:47)
at /srv/node_modules/firebase-admin/lib/messaging/messaging-api-request.js:76:42
at
at process._tickDomainCallback (internal/process/next_tick.js:229:7)
errorInfo:
{ code: 'messaging/unknown-error',
message: 'Auth error from APNS or Web Push Service Raw server response: "{"error":{"code":401,"message":"Auth error from APNS or Web Push Service","status":"UNAUTHENTICATED","details":[{"@type":"type.googleapis.com/google.firebase.fcm.v1.FcmError","errorCode":"THIRD_PARTY_AUTH_ERROR"}]}}"' },
codePrefix: 'messaging' }

Configuration

  • Using APNS Key
  • Happens with both Xcode 11.3.1. & 11.4 Beta
  • Mac OS Catalina 10.15.3
  • podfile.lock excerpts

    • Firebase/Functions (6.18.0):



      • Firebase/CoreOnly


      • FirebaseFunctions (~> 2.5.1)



    • Firebase/Messaging (6.18.0):



      • Firebase/CoreOnly


      • FirebaseMessaging (~> 4.3.0)





        • FirebaseCore (6.6.3):





      • FirebaseCoreDiagnostics (~> 1.2)


      • FirebaseCoreDiagnosticsInterop (~> 1.2)


      • GoogleUtilities/Environment (~> 6.5)


      • GoogleUtilities/Logger (~> 6.5)



Catalyst GoogleUtilities messaging

All 35 comments

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

The error you're getting is likely to cause push notifications to fail on both iOS and macOS Catalyst. Can you try generating a new auth key and uploading it to Firebase console?

I tried with a new APNS key and am seeing the same result. A few more data points:

  • I am using the fcmToken from the callback :
    func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String)
  • I seem to be able to the fcmToken generated on iOS to send a message to the Mac Catalyst instance of the app. The fcmToken from the callback on Catalyst produces the UNAUTHENTICATED error
  • This may or may not be related - UNUserNotificationCenter.current().requestAuthorization(options:) does not show a dialog to the user.

I also see the following warning : 6.18.0 - [Firebase/InstanceID][I-IID003014] Running InstanceID on a simulator doesn't have APNS. Use prod profile by default.

@chliangGoogle could InstanceID be mistaking the Catalyst runtime for a simulator environment?

Looks like that's coming right from GoogleUtilities itself - https://github.com/firebase/firebase-ios-sdk/blob/0dd8dda16557cc56fb93e29fac966e889c3d8347/GoogleUtilities/Environment/third_party/GULAppEnvironmentUtil.m#L203-L211

We should be checking TARGET_OS_MACCATALYST here.

The Swift sample should use #if targetEnvironment(simulator) instead of checking architectures.

This fix will be in the next release, but you can test it out now by installing the pod directly from GitHub.

@morganchen12 This fixed the InstanceID/APNS warning but still hasn't fixed the APNS authentication error.

I can help take a look at. Are you able to reproduce with catalyst?

Yes, I am seeing when I build my app for Catalyst. The same code +
configuration built for iOS does not have the problem. Do I need to make any changes to the bundle ID?

Can you share with us the APNS authentication error?

@chliangGoogle

Error: Auth error from APNS or Web Push Service Raw server response: "{"error":{"code":401,"message":"Auth error from APNS or Web Push Service","status":"UNAUTHENTICATED","details":[{"@type":"type.googleapis.com/google.firebase.fcm.v1.FcmError","errorCode":"THIRD_PARTY_AUTH_ERROR"}]}}"
at FirebaseMessagingError.FirebaseError [as constructor] (/srv/node_modules/firebase-admin/lib/utils/error.js:42:28)
at FirebaseMessagingError.PrefixedFirebaseError [as constructor] (/srv/node_modules/firebase-admin/lib/utils/error.js:88:28)
at new FirebaseMessagingError (/srv/node_modules/firebase-admin/lib/utils/error.js:253:16)
at Function.FirebaseMessagingError.fromServerError (/srv/node_modules/firebase-admin/lib/utils/error.js:283:16)
at Object.createFirebaseError (/srv/node_modules/firebase-admin/lib/messaging/messaging-errors.js:34:47)
at /srv/node_modules/firebase-admin/lib/messaging/messaging-api-request.js:76:42
at
at process._tickDomainCallback (internal/process/next_tick.js:229:7)
errorInfo:
{ code: 'messaging/unknown-error',
message: 'Auth error from APNS or Web Push Service Raw server response: "{"error":{"code":401,"message":"Auth error from APNS or Web Push Service","status":"UNAUTHENTICATED","details":[{"@type":"type.googleapis.com/google.firebase.fcm.v1.FcmError","errorCode":"THIRD_PARTY_AUTH_ERROR"}]}}"' },
codePrefix: 'messaging'

So the error is from server side, meaning your client apns token was not setup correctly.
You mentioned that "UNUserNotificationCenter.current().requestAuthorization(options:) does not show a dialog to the user." This seems like your push notification setting in xcode wan't setup correctly. Can you double check that to make sure the dialog got pop out?

From the api, make sure your have Mac Catalyst 13.0+. https://developer.apple.com/documentation/usernotifications/unusernotificationcenter/1649527-requestauthorization
And make sure you enable push notification in capabilities in xcode and setup the signing and provisioning correctly.

can you also check if you are getting apns token right now?

@chliangGoogle

  • When I call UNUserNotificationCenter.current().requestAuthorization(options:), the callback is called with the result as true. However, there is no authorization dialog shown.
  • The callback func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) is also called with the token
  • Push notifications are enabled in Xcode. Please note that I am using the same setup (signing/provisioning) for my iOS build and that is working. However, when I build and run for Catalyst, I am seeing the error. Do I need to do additional setup for Catalyst? For example, the bundleID for Catalyst is prefixed with "macCatalyst". Does that cause a problem?

"However, when I build and run for Catalyst, I am seeing the error. "
Do you see any error in xcode when you switch? specifically signing errors with your existing push notification provisioning profile?

I see the following errors, not sure if they are related:

[User Defaults] Couldn't write values for keys (
ApplicationAccessibilityEnabled
) in CFPrefsPlistSource<0x600002c21780> (Domain: com.apple.Accessibility, User: kCFPreferencesCurrentUser, ByHost: No, Container: (null), Contents Need Refresh: Yes): setting preferences outside an application's container requires user-preference-write or file-write-data sandbox access

[User Defaults] Couldn't write values for keys (
FullKeyboardAccessFocusRingEnabled
) in CFPrefsPlistSource<0x600002c21780> (Domain: com.apple.Accessibility, User: kCFPreferencesCurrentUser, ByHost: No, Container: (null), Contents Need Refresh: No): setting preferences outside an application's container requires user-preference-write or file-write-data sandbox access

[User Defaults] Couldn't write values for keys (
ApplicationAccessibilityEnabled
) in CFPrefsPlistSource<0x600002c21780> (Domain: com.apple.Accessibility, User: kCFPreferencesCurrentUser, ByHost: No, Container: (null), Contents Need Refresh: No): setting preferences outside an application's container requires user-preference-write or file-write-data sandbox access

[Firebase/Core][I-COR000008] The project's Bundle ID is inconsistent with either the Bundle ID in 'GoogleService-Info.plist', or the Bundle ID in the options if you are using a customized options. To ensure that everything can be configured correctly, you may need to make the Bundle IDs consistent. To continue with this plist file, you may change your app's bundle identifier to 'com.myApp.bundleIF'. Or you can download a new configuration file that matches your bundle identifier from https://console.firebase.google.com/ and replace the current one.

Couldn't read values in CFPrefsPlistSource<0x600002c51780> (Domain: group.myApp.bundleID, User: kCFPreferencesAnyUser, ByHost: Yes, Container: (null), Contents Need Refresh: Yes): Using kCFPreferencesAnyUser with a container is only allowed for System Containers, detaching from cfprefsd

[Firebase/InstanceID][I-IID003014] Error while reading embedded mobileprovision Error Domain=NSCocoaErrorDomain Code=260 "The file “embedded.mobileprovision” couldn’t be opened because there is no such file." UserInfo={NSFilePath=/.../Developer/Xcode/DerivedData/MyApp-bfnufiqtzeksrgetsiycpfkfzngu/Build/Products/Beta-maccatalyst/MyApp.app/embedded.mobileprovision, NSUnderlyingError=0x600000db5fb0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}

I see couple of issues here:

  1. Core refuses the bundle ID as it's not in plist @ryanwilson
  2. Messaging can't detect the right mobileprovision file (assigned this issue to myself)
  3. Regardless Firebase, if the dialog is not popping up, it could mean APNS is still not setup correctly on Apple side. Can you try to send a notification using the APNS token to see if it delivers (this will also rule out Apple side of issues)

@chliangGoogle Regarding 3:
I am currently using the admin send function as described here:
https://firebase.google.com/docs/cloud-messaging/send-message

Do I just substitute the APNS token for the FCM registration token to test 3?

You can try something like this:https://github.com/firebase/firebase-ios-sdk/issues/4042#issuecomment-542359566

I used the following to test: https://github.com/onmyway133/PushNotifications

While I don't see the notification delivered on the device, I don't see an error message either. The PushNotifications app shows a success message.

Edit: Correction. The notifications are being delivered. The first notifications were delayed for some reason.

I see so number 3 is not an issue, we are working on issues 1 and 2.

Looking at the bundleID issue now, also related to #5126

@girishw Please try again with xcode 11.4 which allows to use the same bundle ID as your iOS one.
Screen Shot 2020-03-25 at 5 07 26 PM

I managed to get it working after #5165. So if you can enable it without using the bundle ID prefix with maccatalyst and wait for the next release with #5165 should resolve the issue.

@chliangGoogle I rebuilt my app with Xcode 11.4, Use iOS Bundle Identifier checked. I built with the github sources. I now see the following error message:

{ Error: Requested entity was not found.
at FirebaseMessagingError.FirebaseError [as constructor] (/srv/node_modules/firebase-admin/lib/utils/error.js:42:28)
at FirebaseMessagingError.PrefixedFirebaseError [as constructor] (/srv/node_modules/firebase-admin/lib/utils/error.js:88:28)
at new FirebaseMessagingError (/srv/node_modules/firebase-admin/lib/utils/error.js:253:16)
at Function.FirebaseMessagingError.fromServerError (/srv/node_modules/firebase-admin/lib/utils/error.js:283:16)
at Object.createFirebaseError (/srv/node_modules/firebase-admin/lib/messaging/messaging-errors.js:34:47)
at /srv/node_modules/firebase-admin/lib/messaging/messaging-api-request.js:76:42
at
at process._tickDomainCallback (internal/process/next_tick.js:229:7)
errorInfo:
{ code: 'messaging/registration-token-not-registered',
message: 'Requested entity was not found.' },
codePrefix: 'messaging' }

I verified that messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) is being called and I am using the new FCM token.

Do I need to do anything else to reset my app for the new configuration?

Can you reset your app uninstall it and reinstall again?

@chliangGoogle I am running builds from Xcode to test. I tried deleting the user's account and running a first launch process with authorization of notifications, etc. Still the same result :-(

Are you running on mac or ipad? Is it possible to share your debugLog with me? You can send directly to me.

Sync offline and customer didn't get the latest version of code. @girishw please try again with the patch changes of #5165 and reopen the issue if it still doesn't work for you.

same problem for me, i have pod version 6.21
i accept permission to allow push on my catalyst app
i dont receive push
on IOS it works like a charm

any help ? its something special to do with catalyst ? i add keychain sharing capability as i read it in 6.21 readme, but its change nothing.

The fix is in the next release. Please wait for 6.22 and see if that resolves the issue.

hey hey, i get the 6.22 and test push with cloud messaging test in firebase console, its not working, i don't get notification on my mac with my catalyst app.

Was this page helpful?
0 / 5 - 0 ratings