Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

[iOS] Cloud messaging notifications not working #1859

Open
Wakko90 opened this issue Nov 25, 2021 · 2 comments
Open

[iOS] Cloud messaging notifications not working #1859

Wakko90 opened this issue Nov 25, 2021 · 2 comments

Comments

@Wakko90
Copy link

Wakko90 commented Nov 25, 2021

Hello, I'm working on a NS/Angular project using Firebase. Push notifications from Firebase Cloud Messaging are not received at all on iOS simulator (I cannot test on a real iOS device at the moment).

Here is my configuration:

"@nativescript/firebase": "^11.1.3",
"@nativescript/angular": "~12.0.0",
"@nativescript/core": "~8.0.0"

XCode version 13.0
Simulating an iPhone 13 with iOS 15.0

APN Auth Key is uploaded to my Firebase console

This is my firebase.nativescript.json file

{
    "using_ios": true,
    "using_android": true,
    "analytics": true,
    "firestore": true,
    "realtimedb": false,
    "authentication": true,
    "remote_config": false,
    "performance_monitoring": false,
    "external_push_client_only": false,
    "messaging": true,
    "in_app_messaging": true,
    "crashlytics": false,
    "storage": true,
    "functions": true,
    "facebook_auth": false,
    "google_auth": true,
    "admob": false,
    "dynamic_links": false,
    "ml_kit": false
}

Entitlements file is placed in App_Resources/iOS and this is its content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>aps-environment</key>
	<string>development</string>
</dict>
</plist>

the file App_Resources/iOS/Info.plist contains this value

	<key>UIBackgroundModes</key>
	<array>
  		<string>remote-notification</string>
	</array>

I followed this guide to the letter as requested in the plugin documentation. Anyway i couldn't perform the tasks described in the sections "Initialize Firebase in your app" and "Register for remote notifications" but I guess this plugin should handle that.

my main.ts file


  console.log('initializing firebase');
  firebase.init({
    showNotifications: true,
    showNotificationsWhenInForeground: true,
  }).then(() => {
     console.log('Firebase initialized');
  }).catch(err => {
      console.error(err)
  });


runNativeScriptAngularApp({
  appModuleBootstrap: () => platformNativeScript().bootstrapModule(AppModule),
});

my app.component.ts ngOnInit method

try {
      console.log('setting notifications handlers');

      await firebase.addOnPushTokenReceivedCallback(token => {
        console.log('[Firebase] onPushTokenReceivedCallback:', { token });
            this.authService.saveDeviceToken(token);
      })

      await firebase.addOnMessageReceivedCallback(message => {
        console.log('[Firebase] onMessageReceivedCallback:', { message });
      })
    } catch (error) {
      console.error(error);
    }

When I run the application, I correctly receive the push token via the onPushTokenReceivedCallback

I use Postman to make POST calls to Firebase Messaging service, this is what I send:

{
     "notification": {
       "title": "My title",
       "text": "My text",
       "badge": 1,
       "sound": "default"
     },
     "priority": "High",
     "to": "XXXXXXXXXXXXXX"
   }

and this is the response

{
    "multicast_id": xxxxxxxxxxxxxxxx,
    "success": 1,
    "failure": 0,
    "canonical_ids": 0,
    "results": [
        {
            "message_id": "xxxxxxxxxxxxxxxxxxx"
        }
    ]
}

But in the app the OnMessageReceivedCallback is never fired and no popup comes out on the simulator.

Can someone please help me figure out what I'm doing wrong?

Thanks

@chanyb
Copy link

chanyb commented Dec 24, 2021

now, i faced this issue too

@tomups
Copy link

tomups commented Apr 19, 2022

Push notifications don't work in iOS simulator, only on real device:

https://stackoverflow.com/questions/1811900/can-we-check-push-notification-in-simulator

You can trigger them manually for testing i.e. via terminal commands. But real push notifications coming from Firebase will not work.

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

3 participants