microsoft / appcenter-sdk-cordova

App Center Preview SDK for Cordova
http://appcenter.ms
MIT License
52 stars 27 forks source link

How to detect foreground/background mode after receiving the push notification on iOS #93

Open maciejkoch opened 4 years ago

maciejkoch commented 4 years ago

Description

Hi,

How to detect foreground/background mode after receiving the push notification on iOS? According to the documentation for the Android we can check if message property is empty. How to reach the same on iOS?

if (message === null || message === undefined) {
   // Android messages received in the background don't include a message. On Android, that fact can be used to
   // check if the message was received in the background or foreground. For iOS the message is always present.
   title = 'Android background';
   message = '<empty>';
}

I use Ionic 4 with this plugin: https://ionicframework.com/docs/native/app-center-push

Repro Steps

Please list the steps used to reproduce your issue.

  1. Send the notification
  2. Click on a notification

Details

  1. Which SDK version are you using? 0.3.4
  2. Which OS version did you experience the issue on? Android 8, Android 9
  3. What version of Cordova, Cordova platforms, Cocoapods, and Ruby are you using? Cordova version 8.0.0
  4. What device version did you see this error on? Were you using a simulator or a physical device? Nokia 7Plus, Huawei P10 Lite
  5. What third party plugins are you using? cordova-android-firebase-gradle-release 3.0.0 "cordova-android-firebase-gradle-release" cordova-android-play-services-gradle-release 3.0.0 "cordova-android-play-services-gradle-release" cordova-plugin-actionsheet 2.3.3 "ActionSheet" cordova-plugin-app-version 0.1.9 "AppVersion" cordova-plugin-appcenter-analytics 0.3.4 "App Center Analytics for Cordova" cordova-plugin-appcenter-push 0.3.4 "App Center Push for Cordova" cordova-plugin-appcenter-shared 0.3.4 "App Center shared code for Cordova" cordova-plugin-background-mode 0.7.2 "BackgroundMode" cordova-plugin-browsertab 0.2.0 "cordova-plugin-browsertab" cordova-plugin-camera 4.0.3 "Camera" cordova-plugin-cocoapod-support 1.6.0 "Cordova CocoaPods Dependency Support" cordova-plugin-compat 1.2.0 "Compat" cordova-plugin-contacts 3.0.1 "Contacts" cordova-plugin-device 2.0.2 "Device" cordova-plugin-dialogs 2.0.1 "Notification" cordova-plugin-inappbrowser 3.0.0 "InAppBrowser" cordova-plugin-ionic-keyboard 2.1.3 "cordova-plugin-ionic-keyboard" cordova-plugin-ionic-webview 3.1.2 "cordova-plugin-ionic-webview" cordova-plugin-ms-adal 0.10.1 "ADAL for Cordova" cordova-plugin-network-information 2.0.1 "Network Information" cordova-plugin-splashscreen 5.0.2 "Splashscreen" cordova-plugin-statusbar 2.4.2 "StatusBar" cordova-plugin-whitelist 1.3.3 "Whitelist" cordova-sqlcipher-adapter 0.2.1 "Cordova sqlcipher adapter" uk.co.workingedge.phonegap.plugin.launchnavigator 5.0.4 "Launch Navigator"
annakocheshkova commented 4 years ago

Hi there @maciejkoch! In the PushNotificationReceived callback on iOS, there's no way to distinguish between these modes. However, there are multiple options if you want to achieve that: