react-native-push-notification
react-native-push-notification copied to clipboard
Notifications appear ONLY after opening the app!
Bug
Hi there!
Amazing work with this package and it is working almost flawlessly.
However, some of my android users have reported that their scheduled
notifications are not arriving and are only being shown AFTER they have opened the app.
This can be many notifications being shown at once if more than one scheduled notification already passed.
I did not see any other similar issue being open and wanted to see if anyone else has experienced this issue? All notifications within the app are scheduled locally.
On iOS it hasn't been reported!
Environment info
react-native info
output:
System:
OS: macOS 10.15.3
CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
Memory: 65.34 MB / 16.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 8.9.4 - /usr/local/bin/node
npm: 6.9.0 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 13.5, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
Android SDK:
API Levels: 23, 25, 26, 27, 28
Build Tools: 26.0.2, 26.0.3, 27.0.2, 27.0.3, 28.0.2, 28.0.3
System Images: android-28 | Google Play Intel x86 Atom, android-P | Google APIs Intel x86 Atom
IDEs:
Android Studio: 3.4 AI-183.6156.11.34.5692245
Xcode: 11.5/11E608c - /usr/bin/xcodebuild
npmPackages:
react: 16.8.6 => 16.8.6
react-native: 0.60.4 => 0.60.4
npmGlobalPackages:
create-react-native-app: 1.0.0
react-native-cli: 2.0.1
react-native-git-upgrade: 0.2.7
Library version: "react-native-push-notification": "^3.5.1",
Hi @wmonecke
Does that occure every time ? or only in some users ?
Hi, I have the same Issue, after updating my phone to android 10, it's happening for local notifications, don't know what is causing this.
Hi @hikkary This is probably a deprecation in the Android SDK, will take a look at it.
Can someone share the logic that define the date ? If the date is set in the past, the notification will trigger instantly (like when the app is opened). This is actually the most relevant root cause since AlarmManager is still OK on Android 29.
Hi @wmonecke
Does that occure every time ? or only in some users ?
Hi! This is mainly happening with Android devices. I can't be sure because 90% of my users are Android users.
Can someone share the logic that define the date ? If the date is set in the past, the notification will trigger instantly (like when the app is opened). This is actually the most relevant root cause since AlarmManager is still OK on Android 29.
This is not the issue. I actually had the issue that the notification fired right away if set on the same date but earlier than the current time. I set the date to the next day if the user schedules a day for the current day but for an earlier hour. Something like this:
if (notificationDate.isBefore(moment())) {
notificationDate.add(1, 'days')
}
The current issue is different and has happened many times. You won’t receive the notification at the time you set them but once you open the app in the future you will receive ALL scheduled notifications at once.
So for example, if you schedule notifications for 6 pm, 7 pm, and 8 pm, then by 9 pm you won't have received any notification. However, if you open the app at 9 pm you will get all 3.
Can you share the code when you plan the notification ? (parameters) And the AndroidManifest ?
The example project doesn't have this issue even with API 29.
I need a reproducible example to investigate.
@Dallas62 Yes of course 👍
Schedule Notification:
PushNotification.localNotificationSchedule({
/* Android Only Properties */
id: generatedId, // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
// largeIcon: "@mipmap/ic_notif", // (optional) default: "ic_launcher"
smallIcon: "@mipmap/ic_notif", // (optional) default: "ic_notification" with fallback for "ic_launcher"
vibrate: true, // (optional) default: true
vibration: 300, // vibration length in milliseconds, ignored if vibrate=false, default: 1000
priority: "high", // (optional) set notification priority, default: high
visibility: "public", // (optional) set notification visibility, default: private
importance: "high", // (optional) set notification importance, default: high
allowWhileIdle: true, // (optional) set notification to work while on doze, default: false
ignoreInForeground: false, // (optional) if true, the notification will not be visible when the app is in the foreground (useful for parity with how iOS notifications appear)
/* iOS only properties */
alertAction: "view", // (optional) default: view
userInfo: {
id: generatedId, // number
}, // (optional) default: {} (using null throws a JSON value '<null>' error)
/* iOS and Android properties */
date: new Date(notificationDate.valueOf()),
repeatType: 'week',
message: strings.RoutineComponent.notificationDescription,
title: routine.title,
});
Android Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp">
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.android.vending.BILLING"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION"/>
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="true"
android:theme="@style/AppTheme">
<!-- BUGSNAG -->
<meta-data
android:name="com.bugsnag.android.API_KEY"
android:value=""/>
<meta-data
android:name="com.bugsnag.android.DETECT_NDK_CRASHES"
android:value="true"/>
<!-- GOOGLE ADS -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value=""/>
<!-- GOOGLE MAPS -->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value=""/>
<!-- REACT NATIVE PUSH NOTIFICATION -->
<meta-data
android:name="com.dieam.reactnativepushnotification.notification_channel_name"
android:value=" {...name} "/>
<meta-data
android:name="com.dieam.reactnativepushnotification.notification_channel_description"
android:value=" {...description} "/>
<!-- Change the value to true to enable pop-up for in foreground (remote-only, for local use ignoreInForeground) -->
<meta-data
android:name="com.dieam.reactnativepushnotification.notification_foreground"
android:value="true"/>
<!-- Change the resource name to your App's accent color - or any other color you want -->
<meta-data
android:name="com.dieam.reactnativepushnotification.notification_color"
android:resource="@color/white"/> <!-- or @android:color/{name} to use a standard color -->
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service
android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<!-- MAIN ACTIVITY -->
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
</manifest>
android/app/build.gradle
apply plugin: "com.android.application"
import com.android.build.OutputFile
project.ext.react = [
enableHermes: true,
entryFile: "index.js",
//bundleCommand: "ram-bundle",
]
apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false
def jscFlavor = 'org.webkit:android-jsc:+'
def enableHermes = project.ext.react.get("enableHermes", false);
// Hermes issue with .aab - Reference: https://github.com/facebook/react-native/issues/26400
// configurations.all {
// resolutionStrategy {
// force "com.facebook.soloader:soloader:0.8.0"
// }
// }
android {
compileSdkVersion rootProject.ext.compileSdkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.myapp"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
vectorDrawables.useSupportLibrary = true
renderscriptTargetApi 23
renderscriptSupportModeEnabled true
versionCode 68
versionName "4.6"
multiDexEnabled true
}
dexOptions {
jumboMode true
incremental true
javaMaxHeapSize "4g"
}
signingConfigs {
release {
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
debug {
if (project.hasProperty('MYAPP_DEBUG_STORE_FILE')) {
storeFile file(MYAPP_DEBUG_STORE_FILE)
storePassword MYAPP_DEBUG_STORE_PASSWORD
keyAlias MYAPP_DEBUG_KEY_ALIAS
keyPassword MYAPP_DEBUG_KEY_PASSWORD
}
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
}
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3, "x86_64": 4]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
packagingOptions {
pickFirst '**/armeabi-v7a/libc++_shared.so'
pickFirst '**/x86/libc++_shared.so'
pickFirst '**/arm64-v8a/libc++_shared.so'
pickFirst '**/x86_64/libc++_shared.so'
pickFirst '**/x86/libjsc.so'
pickFirst '**/armeabi-v7a/libjsc.so'
}
}
dependencies {
// enabling multiDex for minSdkVersion below 20 (current is 16)
implementation 'androidx.multidex:multidex:2.0.1'
// react-native
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.facebook.react:react-native:+" // From node_modules
// 3rd party
implementation project(':rn-fetch-blob')
implementation project(':react-native-fs')
implementation project(':react-native-svg')
implementation project(':react-native-video')
implementation project(':react-native-share')
implementation project(':lottie-react-native')
implementation project(':bugsnag-react-native')
implementation project(':react-native-location')
implementation project(':react-native-purchases')
implementation project(':react-native-view-shot')
implementation project(':react-native-keep-awake')
implementation project(':react-native-fast-image')
implementation project(':react-native-date-picker')
implementation project(':react-native-device-info')
implementation project(':react-native-vector-icons')
implementation project(':react-native-localization')
implementation project(':react-native-splash-screen')
implementation project(':react-native-google-places')
implementation project(':react-native-linear-gradient')
implementation project(':@react-native-community_blur')
implementation project(':react-native-image-crop-picker')
implementation project(':react-native-push-notification')
implementation project(':@react-native-community_google-signin')
implementation project(':@react-native-community_async-storage')
// react-native-router-flux
implementation project(':react-native-screens')
implementation project(':react-native-reanimated')
implementation project(':react-native-gesture-handler')
implementation project(':react-native-safe-area-context')
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02'
// react-native-firebase
implementation project(':react-native-firebase')
implementation "com.google.android.gms:play-services-base:16.0.1"
// implementation 'com.google.firebase:firebase-analytics:17.0.1'
implementation 'com.google.firebase:firebase-analytics:17.3.0'
implementation 'com.google.firebase:firebase-core:17.0.1'
implementation "com.google.firebase:firebase-database:17.0.0"
implementation 'com.google.firebase:firebase-auth:18.1.0'
implementation "com.google.firebase:firebase-storage:17.0.0"
implementation 'com.google.firebase:firebase-firestore:20.2.0'
implementation "com.google.firebase:firebase-ads:18.1.1"
// implementation "com.google.firebase:firebase-messaging:19.0.1"
implementation 'me.leolin:ShortcutBadger:1.1.21@aar'
implementation "com.google.android.gms:play-services-location:16.0.0"
if (enableHermes) {
def hermesPath = "../../node_modules/hermesvm/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
apply plugin: 'com.google.gms.google-services'
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
Were you able to reproduce it ? Or just user's report ?
I will test on a device tomorrow, I don't see anything that should block (Android Guidelines, Stack Overflow). You are running the task every week, maybe it's related to that (reboot ? too long for the system ? some energy / doze mode kill the app ?)
Do you see a kind of device in report or Android version to find something in common between users ?
@Dallas62 I am not able to reproduce it.
It seems the first few notifications work well and it starts sometime in the future. All my users tell me they have allowed all possible permissions (batter manager, etc.) and that it still happens. I don't see any errors or crashes in my logs which is pretty weird.
Hi @wmonecke
Wasn't able to reproduce it actually, but I think one of my application as this kind of bug. I need to find something in common between Android to know where to look.
Maybe reboot, low battery or Android system which kill the alarm manager.
I am getting same reports from my Android users, but I also couldn't find a way to reproduce yet! Some users receive the notifications only when they open the app.
Will keep you updated if I can find a way to reproduce this.
One thing that I once could see is that low battery caused the app to not send notifications anymore on a friends phone, maybe its related to that?
Also just received a report that it happened to a user after updating the phone
Hi @zwenza Do you have some information on devices ? Like manufacturers, Android Version and maybe the model could help.
@Dallas62 I gathered some informations about users who have this problem and you can see a very clear trend:
One user reported it happened after upgrading to Android 10.
Also getting reports about the issue from people with a Samsung Galaxy S7 edge, Samsung Galaxy S9, Samsung Galaxy A50, Samsung Galaxy J7 Prime 2, Samsung Galaxy A51, Samsung Galaxy A20.
So seems that the Samsung Galaxy phones are the ones causing the trouble...
@Dallas62 I don't think the problem is with the Android update. I haven't received any update for my old Elephone S7 (Android 7.1.1) for years and it doesn't work. All other devices work...
Hi @phan21 Good to hear you are able to reproduce this issue, can tou share the AndroidManifest of your App ?
I will recheck from scratch how this is working, there is probably information in stackoverflow or specialized forum.
Of course. But my manifest is almost the same as in the example on github here
Hope it helps manifest.txt
Same problem here, using a Samsung M30 Android 10, all notifications came after user enter the app
Just to be sure that tis is a "library issue" are you sure that the notifications was scheduled before the app start ? Then do you know if this behavior appear after a restart / reboot or always ?
Yes! The notification time is set correctly and the notif should have fired before opening the app. I am experiencing this currently on my personal Xiaomi phone.
All the best and stay safe,
Walter Monecke software engineer @ urban hero
On Tue, Aug 18, 2020, 23:19 Boris Tacyniak [email protected] wrote:
Just to be sure that tis is a "library issue" are you sure that the notifications was scheduled before the app start ? Then do you know if this behavior appear after a restart / reboot or always ?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/zo0r/react-native-push-notification/issues/1574#issuecomment-675726012, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFZB7VMQXPUQMEDYBD2KLPDSBLV6NANCNFSM4PRW2K5Q .
Here is a video:
https://streamable.com/fkks03
This video is using the options like in the comment: https://github.com/zo0r/react-native-push-notification/issues/1574#issuecomment-669255696
allowWhileIdle: true
?
If yes, do you see the notification pop-up in the next 24h without openning the application ?
I will take time today on this.
@Dallas62 Yes it has allowWhileIdle: true
just like in my comment above.
If yes, do you see the notification pop-up in the next 24h without openning the application ?
I will test this out today and let you know :)
Thank you for your hard work!
I will link some threads with possible workarounds, since I'm not able to reproduce this, I try to find workaround without editing library at first:
https://stackoverflow.com/questions/35380310/alarmmanager-not-working-on-samsung-devices-in-lollipop
The only way to "fix" this is to inform the Users of your app about the situation and show them how to whitelist your app in Smart Manager. We've had to setup a website with step-by-step instructions showing how to do this for our users.
https://stackoverflow.com/questions/34074955/android-exact-alarm-is-always-3-minutes-off/34085645#340856457 https://issuetracker.google.com/issues/37070267
Edit: Looks like this issue does not occur when there is keyword "alarm" or "alert" in the app package name
Need changes in library:
https://stackoverflow.com/questions/35915326/how-to-schedule-alarm-without-alarmmanager-api
Replace AlarmManager
by JobScheduler
=> time is inexact.
As far as I search, rename the app package seems to be the best solution. Will see if this is working, then find if a workaround with code is possible. Rename the package is really breaking.
https://developer.android.com/studio/build/application-id
Every Android app has a unique application ID that looks like a Java package name, such as com.example.myapp. This ID uniquely identifies your app on the device and in Google Play Store. If you want to upload a new version of your app, the application ID (and the certificate you sign it with) must be the same as the original APK—if you change the application ID, Google Play Store treats the APK as a completely different app. So once you publish your app, you should never change the application ID.
Maybe a application-variant could work...
Does someone able to test the workaround with the application id ? For testing purposes only, expect if your application is not released yet 😅
Was just looking through your shared link https://stackoverflow.com/questions/34074955/android-exact-alarm-is-always-3-minutes-off/34085645#340856457
Can anyone test if simply adding a package containing alarm
fixes the issue or if the Samsung Smart Manager kills everything that doesn't have alarm
in the application-id?
If changing the application id is the only way this can work, it would be really terrible 😅
I think if this is only package name, this is "not" a problem. I read somewhere that application id and package can be different in AndroidManifest.
But without a test, it's hard to know...
@Dallas62 Hi there! I waited 24H but no notification appeared sadly. I had to open the app for it to show :(
I faced same issue. @Dallas62 How is it going?
The issue is stuck, waiting for tests described above.