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 tap property on Background use case - iOS Ionic 4 app #96

Closed
Sampath-Lokuge opened this issue Aug 17, 2019 · 5 comments
Closed

No tap property on Background use case - iOS Ionic 4 app #96

Sampath-Lokuge opened this issue Aug 17, 2019 · 5 comments

Comments

@Sampath-Lokuge
Copy link

Sampath-Lokuge commented Aug 17, 2019

Hi,

There is no tap property on iOS device background use case. Hence it shows the notification 2 times. i.e. it always fires // Received in foreground section on fcmListeners() method. i.e. it shows system tray notification and custom notification where I have created for a foreground use case.

Note: Here I use firebase console dashboard to send the push. i.e. no API call

FCM dashboard custom property: https://imgur.com/cE9Yxwk

Note: No issues on the Killed use case. i.e. it doesn't fire the custom notification. only the system tray notification shows. This is the behavior where I need background use case too.

Note: No issues on Android device. i.e. it works fine on all 3 use cases.

service.ts

  async init() {
    if (this.platform.is('android')) {
      this.fcmToken = await this.firebase.getToken();
    } else if (this.platform.is('ios')) {
      const res = await this.firebase.hasPermission();
      if (!res.isEnabled) {
        await this.firebase.grantPermission();
        this.fcmToken = await this.firebase.getToken();
      }
    }
    this.fcmListeners();
    console.log('this.fcmToken', this.fcmToken);
  }

  fcmListeners() {
    this.firebase.onMessageReceived().subscribe(async (data: any) => {
      if (data.tap === 'background') {// when user tapped the background notification
        console.log('background notification', JSON.stringify(data, null, 4));
      } else { // Received in foreground
        console.log('Received in foreground', JSON.stringify(data, null, 4));
        this.showToastService.showFcmToast(data.title, data.message, data); // custom toast
      }
    });
  }

app.componet.ts

initializeApp() {
    this.platform.ready().then(() => {
      if (this.platform.is('cordova')) {
        this.firebaseCloudMessagingService.init(); // fcm
      }
    });
  }

package.json

"cordova-plugin-firebasex": "^6.0.7",

ionic info

Ionic:

   Ionic CLI                     : 5.2.4
   Ionic Framework               : @ionic/angular 4.7.4
   @angular-devkit/build-angular : 0.801.3
   @angular-devkit/schematics    : 8.1.3
   @angular/cli                  : 8.1.3
   @ionic/angular-toolkit        : 2.0.0

Cordova:

   Cordova CLI       : 9.0.0 (cordova-lib@9.0.1)
   Cordova Platforms : ios 5.0.1
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 4.1.1, (and 8 other plugins)

Utility:

   cordova-res : not installed
   native-run  : not installed

System:

   ios-deploy : 1.9.4
   ios-sim    : 8.0.1
   NodeJS     : v10.14.2 (/usr/local/bin/node)
   npm        : 6.5.0
   OS         : macOS High Sierra
   Xcode      : Xcode 10.1 Build version 10B61

This is the payload comes when taps the system notification. i.e. it always goes to the // Received in foreground section on fcmListeners() method.

{
    "google.c.a.e": "1",
    "aps": {
        "alert": {
            "title": "Firebase Push",
            "body": "Test Firebase Push"
        }
    },
    "title": "Firebase Push",
    "gcm.n.e": "1",
    "google.c.a.c_id": "4193883769168521163",
    "message": "Test Firebase Push",
    "google.c.a.udt": "0",
    "gcm.message_id": "1566044177059408",
    "google.c.a.ts": "1566044177",
    "messageType": "notification"
}
@brandPittCode
Copy link

I have exactly the same problem with Ionic4; there is no tap property for iOS. I've also set notification_foreground: 'true', but it doesn't show the native notification. In Android it works well.

Config:

"cordova": "^9.0.0",
"cordova-android": "8.0.0",
"cordova-ios": "5.0.1",
"cordova-plugin-firebasex": "6.0.6",

@papattes
Copy link

papattes commented Aug 27, 2019

Hi !
I had the same problem. Looking at the logs I noticed that in the didReceiveRemoteNotification () method the TAP variable was not instantiated.

This piece of code must be added to the AppDelegate+FirebasePlugin.m file at line 150:

NSString* tap;
if([self.applicationInBackground isEqual:[NSNumber numberWithBool:YES]]){
    tap = @"background";
}else{
    tap = @"foreground";
    
}
[mutableUserInfo setValue:tap forKey:@"tap"];
if([mutableUserInfo objectForKey:@"messageType"] == nil){
    [mutableUserInfo setValue:@"notification" forKey:@"messageType"];
}

@Horst1102
Copy link

I can confirm the problem.

@papattes solution fixes the problem.

@Sampath-Lokuge
Copy link
Author

@papattes Can't you create a PR for your solution?

@papattes
Copy link

@Sampath-Lokuge I created it, however, it added it on the arnesson/cordova-plugin-firebase repo.
When I click that new PR, I am redirected automatically to this repository. How to do ?

@dpa99c dpa99c closed this as completed in 471e1bf Aug 30, 2019
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

4 participants