Background notification callback not executed until app is opened on iOS #218
Description
Hi,
I'm trying to incorporate background (silent) push notifications in our app. We observe the behaviour described here on iOS.
- GOOD: When the app is running in the foreground, the push notification is received and notificationCallbackIOS is called as expected.
- BAD: When the app is not in focus, the push notification is received but notificationCallbackIOS is not called until the app is brought to the foreground.
This behaviour is reproducible using the demo app.
I would expect the callback to be executed regardless of the app running in background. Apple states that the app will run for up to 30 sec (source)
When run in debug more using xcode I get a "didReceiveNotification" console message whenever a push notification is received regardless of app state but the callback is not executed until the app is focused.
Which platform(s) does your issue occur on?
- iOS
- Version 11.3.1 and 11.2.6
- (physical device) iPhone 7 and iPhone 6s
Please, provide the following version numbers that your issue occurs with:
- CLI: 4.0.0
- Cross-platform modules: 4.0.0
- Runtime(s): android = 4.0.1 and tns-ios = 4.0.1
- Plugin(s):
"dependencies": {
"nativescript-push-notifications": "../src",
"nativescript-theme-core": "^1.0.4",
"tns-core-modules": "^4.0.0"
},
"devDependencies": {
"awesome-typescript-loader": "~3.4.1",
"babel-traverse": "6.26.0",
"babel-types": "6.26.0",
"babylon": "6.18.0",
"copy-webpack-plugin": "~4.3.1",
"extract-text-webpack-plugin": "~3.0.0",
"lazy": "1.0.11",
"nativescript-css-loader": "~0.26.0",
"nativescript-dev-typescript": "~0.6.0",
"nativescript-dev-webpack": "^0.9.0",
"nativescript-worker-loader": "~0.8.1",
"raw-loader": "~0.5.1",
"resolve-url-loader": "~2.2.1",
"tslint": "^5.8.0",
"typescript": "~2.6.2",
"webpack": "~3.10.0",
"webpack-bundle-analyzer": "^2.8.2",
"webpack-sources": "~1.1.0",
"css-loader": "~0.28.7",
"uglifyjs-webpack-plugin": "~1.1.6"
}
Reproduce
- clone your repo
- cd into demo dir, run: tns prepare ios --release --forDevice --teamId XXXXX
- opened the app in xcode
- configured the demo app for Push Notifications
- run the app on a physical device
- Your app runs and provides an access token for me to use
I use the following message to trigger a silent notification (but I tried many combinations of properties):
{
"aps":{"content-available" : 1},
"data": "hello sir"
}
I get a "didReceiveNotification" whenever a push notification is received no matter what the app state is.
I get Message received! message in your log but only when the app is focused.
Is there something anyone can hint at that can execute code while the app remains in the background?
Cheers