cordova-plugin-fcm-with-dependecy-updated icon indicating copy to clipboard operation
cordova-plugin-fcm-with-dependecy-updated copied to clipboard

OnNotification not fire in ios device foreground and background ionic3?

Open kapilSoni101 opened this issue 5 years ago • 45 comments
trafficstars

Hi Team, I have implemented push notification its working properly android in both foreground / background state and but in IOS onNotification doesn’t trigger when the app is in foreground or background but its working only if app is killed only. team can you please me why onNotification not fire in foreground?

this.fcm.onNotification().subscribe(data => {
    if (data.wasTapped) {
        console.log(data.wasTapped);
        //redirectPageViaNotificationType for redirect page...
        this.redirectPageViaNotificationType(data);
    } else {
        //Notification was received in foreground. Maybe the user needs to be notified
        // if application open, show
        let confirmAlert = this.alertCtrl.create({
            title: ( < any > data).title,
            message: ( < any > data).body,
            buttons: [{
                text: 'Ignore',
                role: 'cancel'
            }, {
                text: 'View',
                handler: () => {
                    //redirectPageViaNotificationType for redirect page...
                    this.redirectPageViaNotificationType(data);
                }
            }]
        });
        confirmAlert.present();
    }
});

e5460425a92740beecb422603101729432c40069_2_666x500

Can you please team help me i have stuck above issue from 1 week?

kapilSoni101 avatar Jun 16 '20 05:06 kapilSoni101

Would you share your package.json?

andrehtissot avatar Jun 16 '20 15:06 andrehtissot

Check below package.json file sir :

{
  "name": "Heulo",
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "http://ionicframework.com/",
  "private": true,
  "scripts": {
    "start": "ionic-app-scripts serve",
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "lint": "ionic-app-scripts lint"
  },
  "dependencies": {
    "@angular/animations": "5.2.11",
    "@angular/common": "5.2.11",
    "@angular/compiler": "5.2.11",
    "@angular/compiler-cli": "5.2.11",
    "@angular/core": "5.2.11",
    "@angular/forms": "5.2.11",
    "@angular/http": "5.2.11",
    "@angular/platform-browser": "5.2.11",
    "@angular/platform-browser-dynamic": "5.2.11",
    "@ionic-native/analytics-firebase": "^4.20.0",
    "@ionic-native/app-version": "^4.12.2",
    "@ionic-native/calendar": "^4.14.0",
    "@ionic-native/camera": "^4.16.0",
    "@ionic-native/core": "~4.12.0",
    "@ionic-native/date-picker": "^4.14.0",
    "@ionic-native/device": "^4.15.0",
    "@ionic-native/fabric": "^4.20.0",
    "@ionic-native/facebook": "^4.17.0",
    "@ionic-native/fcm": "^4.18.0",
    "@ionic-native/file": "^4.16.0",
    "@ionic-native/file-path": "^4.16.0",
    "@ionic-native/file-transfer": "^4.16.0",
    "@ionic-native/globalization": "^5.0.0",
    "@ionic-native/google-analytics": "^4.20.0",
    "@ionic-native/google-plus": "^4.17.0",
    "@ionic-native/image-picker": "^4.15.0",
    "@ionic-native/in-app-browser": "^4.18.0",
    "@ionic-native/ionic-webview": "^5.0.0-beta.11",
    "@ionic-native/keyboard": "^4.15.0",
    "@ionic-native/network": "^4.17.0",
    "@ionic-native/photo-library": "^4.15.0",
    "@ionic-native/social-sharing": "^4.15.0",
    "@ionic-native/splash-screen": "^4.20.0",
    "@ionic-native/status-bar": "~4.12.0",
    "@ionic-native/youtube-video-player": "^4.17.0",
    "@ionic/storage": "^2.1.3",
    "@ngx-translate/core": "^9.1.1",
    "@ngx-translate/http-loader": "^3.0.1",
    "angular-moment-timezone": "^1.7.1",
    "cordova": "^7.1.0",
    "cordova-android": "6.4.0",
    "cordova-android-play-services-gradle-release": "^1.4.4",
    "cordova-android-support-gradle-release": "^2.0.1",
    "cordova-annotated-plugin-android": "^1.0.4",
    "cordova-fabric-plugin": "^1.1.14-dev",
    "cordova-ios": "4.5.5",
    "cordova-play-services-version-adapter": "^1.0.2",
    "cordova-plugin-add-swift-support": "2.0.2",
    "cordova-plugin-analytics": "^2.0.0",
    "cordova-plugin-app-version": "^0.1.9",
    "cordova-plugin-badge": "^0.8.8",
    "cordova-plugin-calendar": "^5.1.2",
    "cordova-plugin-camera": "^4.0.3",
    "cordova-plugin-cocoapod-support": "^1.6.2",
    "cordova-plugin-datepicker": "^0.9.3",
    "cordova-plugin-device": "^2.0.2",
    "cordova-plugin-facebook4": "^3.1.0",
    "cordova-plugin-fcm-with-dependecy-updated": "^2.3.0",
    "cordova-plugin-file": "^5.0.0",
    "cordova-plugin-file-transfer": "^1.7.1",
    "cordova-plugin-filepath": "^1.4.2",
    "cordova-plugin-google-analytics": "^1.8.6",
    "cordova-plugin-googleplus": "^5.3.2",
    "cordova-plugin-inappbrowser": "^3.0.0",
    "cordova-plugin-ionic-keyboard": "^2.1.2",
    "cordova-plugin-ionic-webview": "^1.2.1",
    "cordova-plugin-local-notification": "^0.9.0-beta.2",
    "cordova-plugin-network-information": "^2.0.1",
    "cordova-plugin-photo-library": "^2.1.1",
    "cordova-plugin-splashscreen": "^5.0.2",
    "cordova-plugin-telerik-imagepicker": "^2.2.2",
    "cordova-plugin-whitelist": "^1.3.3",
    "cordova-plugin-x-socialsharing": "^5.4.1",
    "cordova-plugin-youtube-video-player": "^2.1.0",
    "cordova-sqlite-storage": "^2.4.0",
    "es6-promise-plugin": "^4.2.2",
    "ionic-angular": "3.9.2",
    "ionicons": "3.0.0",
    "moment": "^2.24.0",
    "run": "1.4.0",
    "rxjs": "5.5.11",
    "sw-toolbox": "3.6.0",
    "zone.js": "0.8.26"
  },
  "devDependencies": {
    "@ionic/app-scripts": "3.2.0",
    "typescript": "~2.6.2"
  },
  "description": "An Ionic project",
  "cordova": {
    "plugins": {
      "cordova-plugin-whitelist": {},
      "cordova-plugin-device": {},
      "cordova-plugin-ionic-keyboard": {},
      "cordova-sqlite-storage": {},
      "cordova-plugin-datepicker": {},
      "cordova-plugin-calendar": {
        "CALENDAR_USAGE_DESCRIPTION": " "
      },
      "cordova-plugin-x-socialsharing": {},
      "cordova-plugin-photo-library": {
        "PHOTO_LIBRARY_USAGE_DESCRIPTION": "Select Photos"
      },
      "cordova-plugin-telerik-imagepicker": {
        "PHOTO_LIBRARY_USAGE_DESCRIPTION": "Select Image"
      },
      "cordova-plugin-file": {},
      "cordova-plugin-filepath": {},
      "cordova-plugin-file-transfer": {},
      "cordova-android-play-services-gradle-release": {
        "PLAY_SERVICES_VERSION": "11.6.2"
      },
      "cordova-plugin-camera": {},
      "cordova-plugin-youtube-video-player": {},
      "cordova-plugin-network-information": {},
      "cordova-plugin-local-notification": {},
      "cordova-plugin-inappbrowser": {},
      "cordova-android-support-gradle-release": {
        "ANDROID_SUPPORT_VERSION": "26.+"
      },
      "cordova-plugin-fcm-with-dependecy-updated": {},
      "cordova-plugin-app-version": {},
      "cordova-plugin-ionic-webview": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-google-analytics": {
        "GMS_VERSION": "11.0.1"
      },
      "cordova-plugin-add-swift-support": {}
    },
    "platforms": [
      "android",
      "ios"
    ]
  }
}

kapilSoni101 avatar Jun 17 '20 03:06 kapilSoni101

Same problem for me?

{
  "name": "NewAppy",
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "http://ionicframework.com/",
  "private": true,
  "scripts": {
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "lint": "ionic-app-scripts lint",
    "ionic:build": "ionic-app-scripts build",
    "ionic:serve": "ionic-app-scripts serve"
  },
  "dependencies": {
    "@angular/common": "5.0.3",
    "@angular/compiler": "5.0.3",
    "@angular/compiler-cli": "5.0.3",
    "@angular/core": "5.0.3",
    "@angular/forms": "5.0.3",
    "@angular/http": "5.0.3",
    "@angular/platform-browser": "5.0.3",
    "@angular/platform-browser-dynamic": "5.0.3",
    "@ionic-native/core": "4.4.0",
    "@ionic-native/fcm": "^4.20.0",
    "@ionic-native/native-storage": "^4.20.0",
    "@ionic-native/splash-screen": "4.4.0",
    "@ionic-native/status-bar": "4.4.0",
    "@ionic-native/toast": "^4.20.0",
    "@ionic/storage": "2.1.3",
    "cordova-android": "^8.0.0",
    "cordova-ios": "^5.1.1",
    "cordova-plugin-apprate": "^1.1.11",
    "cordova-plugin-console": "^1.0.2",
    "cordova-plugin-device": "^2.0.1",
    "cordova-plugin-dialogs": "^2.0.2",
    "cordova-plugin-fcm-with-dependecy-updated": "^6.4.3",
    "cordova-plugin-geolocation": "^2.1.0",
    "cordova-plugin-image-picker": "^1.1.0",
    "cordova-plugin-inappbrowser": "^3.2.0",
    "cordova-plugin-ionic-keyboard": "^2.0.5",
    "cordova-plugin-ionic-webview": "^4.1.3",
    "cordova-plugin-splashscreen": "^5.0.2",
    "cordova-plugin-statusbar": "^2.1.1",
    "cordova-plugin-transport-security": "^0.1.1",
    "cordova-plugin-whitelist": "^1.3.3",
    "cordova-plugin-x-socialsharing": "^5.0.10",
    "ion-multi-picker": "^2.1.2",
    "ionic-angular": "3.9.2",
    "ionic-calendar-date-picker": "^0.1.2",
    "ionicons": "3.0.0",
    "node-gyp": "^5.0.3",
    "rxjs": "5.5.2",
    "sw-toolbox": "3.6.0",
    "zone.js": "0.8.18"
  },
  "devDependencies": {
    "@ionic/app-scripts": "3.1.8",
    "cordova-plugin-apprate": "^1.5.0",
    "node-sass": "^4.12.0",
    "typescript": "2.4.2"
  },
  "description": "An Ionic project",
  "cordova": {
    "plugins": {
      "cordova-plugin-whitelist": {},
      "cordova-plugin-device": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-ionic-keyboard": {},
      "cordova-plugin-console": {},
      "cordova-plugin-statusbar": {},
      "cordova-plugin-image-picker": {},
      "cordova-plugin-x-socialsharing": {},
      "cordova-plugin-geolocation": {},
      "cordova-plugin-transport-security": {},
      "cordova-plugin-nativestorage": {},
      "cordova-plugin-apprate": {},
      "cordova-plugin-ionic-webview": {},
      "cordova-plugin-inappbrowser": {},
      "cordova-plugin-fcm-with-dependecy-updated": {}
    },
    "platforms": [
      "android",
      "ios"
    ]
  }
}

omicronsrl avatar Jun 17 '20 06:06 omicronsrl

@kapilSoni101 The version [email protected] is far outdated, and will stop being accepted to Apple's Store in December, due its use of the old iOS webview. Upgrading and would be the first step, I also recommend that you check the changelog summary in the Readme to catch up.

Also, your version of cordova-plugin-local-notification has incompatibilities issues fixed in newer versions of cordova-plugin-fcm-with-dependecy-updated.

Alternatively: You could remove @ionic-native/fcm and upgrade to [email protected], which includes ionic support.

andrehtissot avatar Jun 17 '20 10:06 andrehtissot

@omicronsrl As your situation appears very different than @kapilSoni101, I've created #107.

andrehtissot avatar Jun 17 '20 10:06 andrehtissot

@kapilSoni101 I'm closing this issue as completing the steps should enable your app to work as intended. If you find any issues, let me know.

andrehtissot avatar Jun 17 '20 10:06 andrehtissot

@andrehtissot : Sir i have followed your instruction but during run app in xcode i got #import "Firebase.h" file not found.check below attached image:

Screenshot 2020-06-17 at 9 21 16 PM

can you tell me how to fix?

kapilSoni101 avatar Jun 17 '20 15:06 kapilSoni101

@ kapilSoni101 Yes, of course.

Back in the day, the plugin shipped a copy of the google sdk. Which creates certain problems when more than one plugin requires that sdk. Hence, the adoption of Cocoapods, which is managed automatically by cordova, and source-optimized by this plugin.

Do you have cocoapods installed? Would you share the log result of running the install plugin command?

andrehtissot avatar Jun 17 '20 16:06 andrehtissot

@andrehtissot - sir in machine cocoapods is installed and in ios folder podfile is generated.but if hit pod install I got below error- " You can not run cocoapods as a root? Which plugin sir?

kapilSoni101 avatar Jun 17 '20 16:06 kapilSoni101

Yes, you shouldn'd ever, for your system's safety. So I recommend to install cocoapods as a user, not as root (no "sudo"). But if you want to force it, there are ways https://stackoverflow.com/questions/23190064/cant-run-sudo-pod-install-after-updating-to-cocoapods-0-32-1-with-error-you-ca

andrehtissot avatar Jun 17 '20 16:06 andrehtissot

@andrehtissot - sir I have install pod without sudo and error is removed.check log after pod install-

15924126521095153325823608900621 Then in xcode I got another issue

15924126961932906386910033495329

kapilSoni101 avatar Jun 17 '20 16:06 kapilSoni101

@andrehtissot - sir i have fixed above issue and notification is received in xcode log but not appear in the mobile device ?

kapilSoni101 avatar Jun 18 '20 12:06 kapilSoni101

@kapilSoni101

  1. Would you share the log, so I can have an idea of how the plugin behaved? You can react tokens or user identifiable information, of course.
  2. Have you added the call to request user's notification permission?
  3. Feels weird to be called "sir", we are all developers helping each other :)

andrehtissot avatar Jun 18 '20 15:06 andrehtissot

@andrehtissot: i have added 2 different log for background and foreground state check below image: IMG20200618205407

IMG20200618205326

during push notification, now onNotification not fire again.i am not understand what's the issue?

  1. Yes, during app launch 1st check the permission.

  2. I have tried with cordova-plugin-firebase for test notification but different scenario here, notification is received but not showing in mobile device?

kapilSoni101 avatar Jun 18 '20 15:06 kapilSoni101

@andrehtissot - any updates for my issue?

kapilSoni101 avatar Jun 19 '20 05:06 kapilSoni101

Thank you @kapilSoni101.

Did you kept cordova-plugin-firebase installed? The log messages bellow are not from cordova-plugin-fcm-with-dependecy-updated: Screenshot 2020-06-19 at 17 38 54

Another plugin is responding the push instead. Would you share your package.json again? I believe some packages have changed.

andrehtissot avatar Jun 19 '20 15:06 andrehtissot

@andrehtissot - I have installed Cordova firebase plugin in seperate dummy project.above log is from fcm-with-dependency plugin.

kapilSoni101 avatar Jun 19 '20 16:06 kapilSoni101

@kapilSoni101 how do you resolved podlock issue ,please i have also same problem. diff: /Podfile.lock: No such file or directory diff: /Manifest.lock: No such file or directory error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.

posdevelopers avatar Jun 20 '20 15:06 posdevelopers

@kapilSoni101 firebase plugin have uiwebview which apple reject.

posdevelopers avatar Jun 20 '20 17:06 posdevelopers

@posdevelopers- 1.I have fixed pod issue via below steps- choose the target > go to Build Phrases > click Link Binary With Libraries > remove all libPods.a files open Terminal > direct to your project > run: pod install 2.yes ur correct actually I have used firebase plugin for check this plugin is working for foreground case or not only. I have stuck above issue last 1week and tried different plugin version as well as different ios platform but nothing worked for me.

kapilSoni101 avatar Jun 20 '20 19:06 kapilSoni101

@kapilSoni101,

It looks like it is an incompatibility with the facebook plugin. Although I wasn't able to confirm.

  1. Please upgrade cordova-plugin-facebook4, so, instead of an internal compile library, it starts using the cocoapods dependency "FBSDKCoreKit". Allowing me to investigate it's internal behavior I can read in https://github.com/facebook/facebook-ios-sdk.

  2. It'd help me to understand the issue if you checked if the method customDidFinishLaunchingWithOptions is called from the plugin's file AppDelegate+FCMPlugin.m. Like in the image bellow: Screenshot 2020-06-22 at 02 45 07

  3. The log messages you presented were not found anywhere, in neither of the dependencies you provided in your package.json.

  4. After hours of installing, fixing unsuported code, and debugging, I'm still far from being able to reproduce the issue. PLEASE provide a hello world app of which I can run and debug.

andrehtissot avatar Jun 22 '20 00:06 andrehtissot

@andrehtissot, 1.can you tell me 1thing if I remove Facebook plugin in such case notification issue is resolved or not? 2.ok I will share hello world app but which plugin we have to install in that project?

kapilSoni101 avatar Jun 22 '20 03:06 kapilSoni101

  1. can you tell me 1thing if I remove Facebook plugin in such case notification issue is resolved or not?

I wasn't able to confirm the source of the issue. I believe it will when you remove the plugin and the Facebook iOS SDK. But without being able to reproduce the issue, this is just an assumption based on multiple plugins implementing/overriding didFinishLaunchingWithOptions.

  1. Ok I will share hello world app but which plugin we have to install in that project?

The ones, in the same versions, that you intend on having in your application. Make sure that this hello world app would present the same problems that you see on your app.

andrehtissot avatar Jun 22 '20 08:06 andrehtissot

@andrehtissot: I wasn't able to confirm the source of the issue. I believe it will when you remove the plugin and the Facebook iOS SDK. But without being able to reproduce the issue, this is just an assumption based on multiple plugins implementing/overriding didFinishLaunchingWithOptions.

Can you tell me 1 thing I have create seperate project for push notification only install push notification plugin but same result not working?

The ones, in the same versions, that you intend on having in your application. Make sure that this hello world app would present the same problems that you see on your app.

ok i will share as soon as possible.

kapilSoni101 avatar Jun 22 '20 08:06 kapilSoni101

Can you tell me 1 thing I have create seperate project for push notification only install push notification plugin but same result not working?

Would you confirm that, in this new app, IOS onNotification doesn’t trigger when the app is in foreground or background. But onNotification does, when the app is completely closed and opened by tapping the notification?

ok i will share as soon as possible.

Thank you.

andrehtissot avatar Jun 22 '20 11:06 andrehtissot

Would you confirm that, in this new app, IOS onNotification doesn’t trigger when the app is in foreground or background. But onNotification does, when the app is completely closed and opened by tapping the notification? Yes i have confirmed IOS onNotification doesn’t trigger when the app is in foreground or background as well as after tap onNotification not fire.

kapilSoni101 avatar Jun 23 '20 05:06 kapilSoni101

Thank you @kapilSoni101, I'm still waiting for the hello world app, and I invite you to try the newer v7.0.1 version.

andrehtissot avatar Jun 28 '20 15:06 andrehtissot

@andrehtissot - actually I was Busy in another project that's the reason I have not shared but I will share tomorrow definitely. Ok I will check newer version and update you.

kapilSoni101 avatar Jun 28 '20 18:06 kapilSoni101

@andretissot :i tried newer version but i got 'Firebase.h' file not found can you tell me how to fix?

kapilSoni101 avatar Jul 01 '20 05:07 kapilSoni101

@kapilSoni101 Which version were you using before upgrading to 7.0.1?

andrehtissot avatar Jul 01 '20 15:07 andrehtissot