React-native-push-notification: [iOS] `onNotification` never called if the app was in "killed" status and received a remote notification.

Created on 29 Sep 2020  Â·  8Comments  Â·  Source: zo0r/react-native-push-notification

Bug

This issue is only on iOS.

On iOS, v5.1.1 called onNotification() when a remote notification arrived even if the app was in "killed" state. (e.g. the user killed the app on purpose.)
However, from v6.0.0, I found that onNotification() is not called int the same situation and it can be reproduced with the example app of this repo. See the Steps To Reproduce section for details.

Environment info

react-native info output:

System:
    OS: macOS 10.15.6
    CPU: (8) x64 Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz
    Memory: 28.91 MB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 12.18.2 - ~/.nvm/versions/node/v12.18.2/bin/node
    Yarn: Not Found
    npm: 6.14.5 - ~/.nvm/versions/node/v12.18.2/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.9.3 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 13.7, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
    Android SDK:
      API Levels: 29, 30
      Build Tools: 29.0.2, 30.0.2
      System Images: android-28 | Google Play Intel x86 Atom, android-30 | Google Play Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 4.0 AI-193.6911.18.40.6626763
    Xcode: 11.7/11E801a - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_265 - /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/bin/javac
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.11.0 => 16.11.0
    react-native: 0.62.2 => 0.62.2
    react-native-macos: Not Found

Library version:
v5.1.1 : onNotification() called
v6.0.0 : onNotification() NOT called
The latest of dev branch : onNotification() NOT called

Steps To Reproduce

  1. Clone zo0r/react-native-push-notification.
  2. cd to example dir
  3. Run npm install and npm run pod-install.
  4. Run npm run ios to start the app with simulator as usual.
  5. After the app launched on iOS simulator, kill the app. (Cmd + Shift + H x 2, and swipe up the app).
  6. Create .apns file like below.
{
    "Simulator Target Bundle": "org.reactjs.native.example.example",
    "aps":{
        "alert":"Hello World",
        "sound":"default",
    }
}
  1. Drag and drop the.apns file to the simulator.
  2. You will see the notification bar and tap it.
  3. The example app will be launched, but the

Note:

From Xcode 11.4, we can test a remote notification on iOS simulator.
https://developer.apple.com/documentation/xcode-release-notes/xcode-11_4-release-notes

Describe what you expected to happen:

  1. Same behavior with v5.1.1.

Most helpful comment

@Dallas62 Thanks for your quick response.

I checked your links and reviewed the example app files of zo0r/react-native-push-notification/, but I cannot find any missing or wrong settings.

Here are what I checked. Everything seems to be already set up correctly.

  • In package.json, have a dependency to react-native-community/push-notification-ios -> OK
  • Correctly setup iOS project by following Readme of react-native-community/push-notification-ios -> OK
    スクリーンショット 2020-09-30 10 27 11
  • Update AppDelegate -> OK.
  • Checked changelog of zo0r/react-native-push-notification. -> OK (In my understanding, it should be OK for iOS if there is a dependency to react-native-community/push-notification-ios)

Do you have any thought for other suspicious setting or code?
Please let me know if there are anything I can help to check.

Thanks,

All 8 comments

Hi @gki
Please refer to the iOS library for this:
https://github.com/react-native-community/push-notification-ios
Regards

Also, if the issue happen after upgrading the library, please refer to:
https://github.com/zo0r/react-native-push-notification/blob/master/CHANGELOG.md

@react-native-community/push-notification-ios is now a peerDependency, please make sure that you installed this library with NPM or YARN.

@Dallas62 Thanks for your quick response.

I checked your links and reviewed the example app files of zo0r/react-native-push-notification/, but I cannot find any missing or wrong settings.

Here are what I checked. Everything seems to be already set up correctly.

  • In package.json, have a dependency to react-native-community/push-notification-ios -> OK
  • Correctly setup iOS project by following Readme of react-native-community/push-notification-ios -> OK
    スクリーンショット 2020-09-30 10 27 11
  • Update AppDelegate -> OK.
  • Checked changelog of zo0r/react-native-push-notification. -> OK (In my understanding, it should be OK for iOS if there is a dependency to react-native-community/push-notification-ios)

Do you have any thought for other suspicious setting or code?
Please let me know if there are anything I can help to check.

Thanks,

I had this exact issue after upgrading to 6.1.1. A few things I needed to do to fix it.
I read a few posts about issues with react-native-splash-screen, which we use so I thought that could be it.
To fix that I set popInitialNotification to false during configure.
Then called PushNotification.popInitialNotification once I was sure our app was ready to handle the notification.
That still didn't work. Then I found that PushNotification.popInitialNotification will not return the notification if you deployed a debug build. Need to deploy a release build.

The only issue I'm still facing is that for iOS onNotification and popInitialNotification return a different format.
In one it is something like {... message: "message body", title: "message title" ... } and in the other it is {... message: {body: "message body", title: "message title"} ...}.

@gki when you mentioned "killed", do you mean user double tap on home button and swipe the app away?

@TommyLeong Yes. That's right.

What I've realized recently is, in "killed" state... none of the delegate and method will get trigger until user launch the app again. Notification banner could appear, but no further background action can be executed. I posted a question at Stackoverflow yesterday

+1

Was this page helpful?
0 / 5 - 0 ratings