Notification not triggered when device is locked with app in foreground
See original GitHub issueNotification is not showing when phone is locked while app is on foreground
Your Environment
- Plugin version: cordova-plugin-local-notification 0.9.0-beta.3 “LocalNotification”
- Platform: iOS
- OS version: 11.2
- Device manufacturer / model: Apple / iPhone SE
- Cordova version (
cordova -v
): 8.0.0 - Cordova platform version (
cordova platform ls
): ios 4.5.4 - Plugin config
- Ionic Version (if using Ionic) 3.9
Expected Behavior
Notification should show up.
Actual Behavior
Notification doesn’t show up
Steps to Reproduce
Reproduce this issue; include code to reproduce, if relevant
- Start the app
- When app is ready, lock the screen without leaving the app
- Register a local notification while the app is in background
- Notification doesn’t show up
Here is the code I use :
let localNotification = {
id: 1,
title: data.title,
text: data.body,
foreground: true,
sound: 'file://assets/ringtones/ios.aiff',
vibrate: true,
actions: [
{id: 'hangon', title: 'Décrocher', launch: true}
],
trigger: {
at: Date.now()
},
data
};
console.log('[] localNotification', localNotification, JSON.stringify(localNotification));
cordova.plugins.notification.local.schedule(localNotification);
Context
I’m trying to register a local notification from a VoIP service. Everything is working fine :
- when the app isn’t open
- when the app is opened then put in background (ie. i’m using gmail)
- when the app is opened then put in background and device locked
But when the app wasn’t in background before locking the device, it fails.
Debug logs
2018-05-04 12:26:20.867588+0200 MyApp[930:362454] [DYMTLInitPlatform] platform initialization successful
2018-05-04 12:26:21.003005+0200 MyApp[930:362403] Apache Cordova native platform version 4.5.3 is starting.
2018-05-04 12:26:21.004050+0200 MyApp[930:362403] Multi-tasking -> Device: YES, App: YES
2018-05-04 12:26:21.020523+0200 MyApp[930:362403] CDVWKWebViewEngine: trying to inject XHR polyfill
2018-05-04 12:26:21.056886+0200 MyApp[930:362403] CDVWKWebViewEngine will reload WKWebView if required on resume
2018-05-04 12:26:21.057016+0200 MyApp[930:362403] Using Ionic WKWebView
2018-05-04 12:26:21.057667+0200 MyApp[930:362403] [CDVTimer][console] 0.077009ms
2018-05-04 12:26:21.057844+0200 MyApp[930:362403] [CDVTimer][handleopenurl] 0.082970ms
2018-05-04 12:26:21.060770+0200 MyApp[930:362403] Unlimited access to network resources
2018-05-04 12:26:21.061014+0200 MyApp[930:362403] [CDVTimer][intentandnavigationfilter] 3.121972ms
2018-05-04 12:26:21.061251+0200 MyApp[930:362403] [CDVTimer][gesturehandler] 0.132084ms
2018-05-04 12:26:21.079318+0200 MyApp[930:362403] [CDVTimer][splashscreen] 17.903924ms
2018-05-04 12:26:21.085788+0200 MyApp[930:362403] [CDVTimer][statusbar] 6.322026ms
2018-05-04 12:26:21.087142+0200 MyApp[930:362403] [CDVTimer][keyboard] 1.073003ms
2018-05-04 12:26:21.087713+0200 MyApp[930:362403] [CDVTimer][socialsharing] 0.292063ms
2018-05-04 12:26:21.089953+0200 MyApp[930:362461] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2018-05-04 12:26:21.090320+0200 MyApp[930:362461] [MC] Filtering mail sheet accounts for bundle ID: com.MyAppavocat.main, source account management: 1
2018-05-04 12:26:21.127196+0200 MyApp[930:362403] [CDVTimer][diagnostic] 39.281011ms
2018-05-04 12:26:21.129420+0200 MyApp[930:362403] iosrtcPlugin#pluginInitialize()
2018-05-04 12:26:21.144429+0200 MyApp[930:362403] PluginGetUserMedia#init()
2018-05-04 12:26:21.144652+0200 MyApp[930:362403] [CDVTimer][iosrtcplugin] 17.265916ms
2018-05-04 12:26:21.149287+0200 MyApp[930:362403] [CDVTimer][localnotification] 4.491925ms
2018-05-04 12:26:21.149378+0200 MyApp[930:362403] [CDVTimer][localnotification] 0.007987ms
2018-05-04 12:26:21.150918+0200 MyApp[930:362403] [CDVTimer][cordovacall] 1.493931ms
2018-05-04 12:26:21.150977+0200 MyApp[930:362403] [CDVTimer][TotalPluginStartup] 93.492985ms
2018-05-04 12:26:21.184412+0200 MyApp[930:362403] createNotificationChecker
2018-05-04 12:26:21.184881+0200 MyApp[930:362403] not coldstart
2018-05-04 12:26:21.223415+0200 MyApp[930:362403] active
2018-05-04 12:26:21.223619+0200 MyApp[930:362403] PushPlugin skip clear badge
2018-05-04 12:26:21.414033+0200 MyApp[930:362403] iosrtcPlugin#onReset() | doing nothing
2018-05-04 12:26:23.913329+0200 MyApp[930:362403] Ionic Native: deviceready event fired after 1670 ms
2018-05-04 12:26:23.913468+0200 MyApp[930:362403] DEVICE READY FIRED AFTER 1390 ms
2018-05-04 12:26:23.913630+0200 MyApp[930:362403] ERROR: the cordova-plugin-ionic plugin is not installed. Install it for better device information for runtime errors.
2018-05-04 12:26:23.915727+0200 MyApp[930:362403] WARN: (getRootNav) is deprecated and will be removed in the next major release. Use getRootNavById instead.
2018-05-04 12:26:23.916471+0200 MyApp[930:362403] registering iosrtc
2018-05-04 12:26:23.918688+0200 MyApp[930:362403] ERROR: Plugin 'HeaderColor' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.
2018-05-04 12:26:23.922767+0200 MyApp[930:362403] [AppUpdateService] needUpdate() Dev
2018-05-04 12:26:23.924336+0200 MyApp[930:362403] loading user from localstorage
2018-05-04 12:26:23.940186+0200 MyApp[930:362403] OPEN database: _ionicstorage
2018-05-04 12:26:23.941711+0200 MyApp[930:362403] new transaction is queued, waiting for open operation to finish
2018-05-04 12:26:23.944560+0200 MyApp[930:362403] [AppUpdateService] getCurrentVersion ENV [object Object]
2018-05-04 12:26:23.954941+0200 MyApp[930:362403] OPEN database: _ionicstorage - OK
2018-05-04 12:26:23.955293+0200 MyApp[930:362403] DB opened: _ionicstorage
2018-05-04 12:26:24.313850+0200 MyApp[930:362403] We have permission to send push notifications
2018-05-04 12:26:24.314920+0200 MyApp[930:362458] Push Plugin VoIP set to true
2018-05-04 12:26:24.317022+0200 MyApp[930:362403] VoIPPush Plugin register success
2018-05-04 12:26:24.320266+0200 MyApp[930:362403] push.onRegister [object Object]
# pausing the app by locking it
2018-05-04 12:26:57.968795+0200 MyApp[930:362403] [App] onPause
# sending the VoIP notification which should create a local one
2018-05-04 12:27:02.121408+0200 MyApp[930:362403] VoIP Notification received
2018-05-04 12:27:02.121535+0200 MyApp[930:362403] Notification received
2018-05-04 12:27:02.121675+0200 MyApp[930:362403] Push Plugin key: alert
2018-05-04 12:27:02.121739+0200 MyApp[930:362403] Push Plugin key: content-available
# here is the payload
2018-05-04 12:27:02.419545+0200 MyApp[930:362403] Push on notification [object Object] {"message":"This one won't show when it's scheduled","additionalData":{}} false
# this scheduling isn't triggered instantly
2018-05-04 12:27:02.420536+0200 MyApp[930:362403] scheduling
2018-05-04 12:27:02.420980+0200 MyApp[930:362403] [] localNotification [object Object] {"id":1,"title":"Local notification.","foreground":true,"sound":"file://assets/ringtones/ios.aiff","vibrate":true,"actions":[{"id":"hangon","title":"Décrocher","launch":true}],"trigger":{"in":0,"unit":"second"},"data":{"message":"This one won't show when it's scheduled","title":"Local notification","additionalData":{"deeplink":"CallPage","receiveCall":true,"coldstart":false,"deeplinkParams":{"id":"bb4410","type":"client"},"username":"Client T","content-available":1,"foreground":false}}}
# receiving another VoIP notification which triggers the 1st one when the phone wakes up
2018-05-04 12:27:22.083873+0200 MyApp[930:362403] VoIP Notification received
2018-05-04 12:27:22.084086+0200 MyApp[930:362403] Notification received
2018-05-04 12:27:22.084253+0200 MyApp[930:362403] Push Plugin key: alert
2018-05-04 12:27:22.084511+0200 MyApp[930:362403] Push Plugin key: content-available
2018-05-04 12:27:22.410697+0200 MyApp[930:362403] Push on notification [object Object] {"message":"This notifications triggers the 1st one because it wakes up the device","title":"Non local notification","additionalData":{"content-available":1,"foreground":false,"coldstart":false,"endCall":true,"deeplink":"HistoryPage"}} false
Issue Analytics
- State:
- Created 5 years ago
- Comments:19
Top Results From Across the Web
App not showing notification when screen is locked or some ...
Go to Settings > Face ID & Passcode (on an iPhone with Face ID) or Touch ID & Passcode (on other iPhone models)....
Read more >Silent notifications works only wh… | Apple Developer Forums
we need to use silent notifications in our app. Seems it works only when the app is in foreground or in debugging. When...
Read more >No notification on lockscreen when app is not in foreground ...
1. Device Settings > Notifications > See All (if needed) > locate Aqua Mail > tap the Toggle switch to enable · 2....
Read more >Restrictions on starting activities from the background
The app receives a notification PendingIntent from the system. In the case of pending intents for services and broadcast receivers, the app can...
Read more >awesome_notifications | Flutter Package - Pub.dev
Notifications could be created at any moment (on Foreground, Background or even when the application is terminated/killed). High trustworthy on receive ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You have a real challenge! There are a few things you must consider:
If your requirement is to create the notification to go off as soon as possible after the screen goes to lock, you must: 1) ask the OS for extra time 2) while your are in the ‘extra time’ (your onPause handler) schedule the notification a few seconds in the future. Do this first so hopefully everything gets done before the OS kills your code.
There’s no assurance that’ll work—I would start looking for other ways to meet your requirement, local notifications might not work.
Not sure as it was ages ago. But something like
ionic cordova plugin rm cordova-plugin-ionic-webview --save
should do it.