I am having a hard time to make this work. What Im using:
1 - The Ionic Framework (version 1.7.14)
2 - Ionic push which is instantiated with: Ionic.Push. So Im not using ngcordova for push
3 -A real device, an Iphone 6s. And I am on OSX.
Since I began sending push notifications from Ionic Push
http://docs.ionic.io/docs/push-overview
something strange happened. I have sent a certain number of pushes both from curl and my own backend application.
The problem was that that badge with number "1" never disappeared from the app icon. I have tried to delete and reinstall the app using Iphone and xcode. But each time the app is installed, the badge with the number 1 is directly shown on the app icon. And even when I go inside the app and then close it, then the badge is still there. Why?
I didnt really understand who should take care of resetting the badge on the app icon. Is it the javascript code in Ionic?
SHouldn't it be managed by default by the OS? Shouldn't the OS clear the badge on the app icon as soon as you open the app that has badges?
I had this code in my js-controller:
var push = new Ionic.Push({
"debug": true,
"pluginConfig": {
"ios": {
"badge": false,
"sound": true
},
"android": {
"iconColor": "#343434"
}
}
});
However, it didnt help. The badge on the app icon is still there.
So as a last thing I did the following:
1 - I removed the code for push in javascript.
2 - I opened "settings" on my iphone and disabled my app to be updated in background.
No luck. The damned badge is still there in the right top corner of my app icon.
Try the following
Change "badge" : false to "badge" : 0
Because badge denotes the total count of notification and not boolean Value for show/hide.
Give it as 0
Hope it helps..
According to Ionic documentation on push, options specified in pluginConfig are passed to Phonegap Push Plugin.
If you look at the plugin documentation you'll see that clearBadge option is what you are looking for, this should be specified both for android and ios, like this:
"pluginConfig": {
"ios": {
"badge": true,
"sound": true,
"clearBadge": true
},
"android": {
"clearBadge": true
}
}
If you are using Phonegap plugin push, you can also do this.
var pushNotification = PushNotification.init(
{ "android": {"senderID": config.senderId, "icon": "notification","clearBadge":"true"},
"ios": {"alert": "true", "badge": "false", "sound": "true", "clearBadge": "true"},
"windows": {} } );
pushNotification.on('notification', function(data) {
pushNotification.setApplicationIconBadgeNumber(function() {
console.log("clear badge success");
}, function() {
console.log("clear badge error");
}, 0); //setting 0 will clear the badge
console.log("notification " + JSON.stringify(data));
});
You can see the doc here
Related
I'm trying to test push notifications in ios simulator with a new Xcode 11.4 feature.
My app has both NotificationService and NotificationContent extensions to change the message before showing it to the user.
To send a notification to the simulator I'm using terminal command:
xcrun simctl push <simulator_id> <app_bundle_id> push.apns
My push.apns is like this:
{
"Simulator Target Bundle": "app_bundle_id",
"aps":{
"category": "NewOrder",
"alert": {
"loc-key": "NOTIFICATION_KEY",
"loc-args": ["3"]
},
"badge": 1,
"sound": "default",
"types": ["order.created"],
"storeId": "4616",
"mutable-content": 1,
"link": "my-app://orders/3",
"thread-id": "OrderThreadId"
}
}
I see the notification on the screen, but it seems that the "link" attribute is not working. When I tab on a push, I expect to see, in this case, the screen of the third order, but I see the main screen of the app.
I'll be appreciated for any help with this. Thanks.
I am trying to implement cache meachanism for FCM on IOS. I am using Xamarin Forms with CrossGeeks FirebasePushNotificationPlugin
Push notification service works fine. I am using payload pattern as below
{
"data": {
"message" : "my_custom_value",
"other_key" : true,
"body":"test"
},
"notification": {
"body" : "hello",
"title": "firebase",
"sound": "default",
"content_available" : true
},
"priority": "high",
"condition": "'general' in topics"
}
Above pattern appears delivered notification as alert on IOS main screen.
I have written a Dependency Service for getting undeleted or unopened accumulated notifications when app starts. Dependency Service include below codes
await UNUserNotificationCenter.Current.GetDeliveredNotificationsAsync();
When I use above payload, I can get accumulated notifications. But when I use payload pattern as below, I can not.
{
"data": {
"message" : "my_custom_value",
"other_key" : true,
"body":"test"
},
"notification": {
"content_available" : true
},
"priority": "high",
"condition": "'general' in topics"
}
Actually I would like to send 2 payload types for every notification for my cache mechanism because of prevent the user's delete action. After that, I would like to show cached notifications without any lost in my app's notification page.
Shortly my question about "I am not getting silent payload values from UNUserNotificationCenter this approach is possible or not?"
Or can I prevent the user's notification delete action from IOS main screen when my app is terminated.
Note: My minimum OS version is 10.0 in info.plist
Thank you in advance.
I'm using the phonegap-plugin-push on my ionic3 app and I've been facing this issue with the iOS platform (android is ok). When the app is in background/foreground everything works as expected. When the app is not running however, I get the message on the notification tray but neither tapping the notification or the app icon triggers the on('notification') event, it simply runs and ignore the incoming notification.
I'm using the { ... content-available: 1} in the aps json message as suggested by the docs, but it doesn't seem to have any effect (though, it does have effect on Android), the ionic app itself never gets the message even though the device received it and displayed it on the tray.
Bellow, I show my configurations and a sample message sent to the push services. If anyone have any idea on how to sort this out will be appreciated, I've tested on ios 8.x and ios 11.x, both have presented the same behavior.
const options: PushOptions = {
android: {
senderID: '*************',
icon: 'ic_stat_ic_notification'
},
ios: {
alert: 'true',
badge: 'true',
sound: 'true'
},
windows: {}
};
platform.ready().then(() => {
push.on('registration').subscribe((data: EventResponse) => {
// register data.registrationId
});
push.on('notification').subscribe((data: EventResponse) => {
alert(data.message)
});
});
Sample message:
{
"aps": {
"alert": "This is a Push",
"badge": 1,
"content-available": 1
},
"payload": {
"type": "news"
}
}
This is too long of a comment. It's more of an indirect answer.
1) or the app icon triggers the on('notification') event <-- that's expected. Imagine your app just received 10 notifications. How should it know which notification you intended to open?
2) neither tapping the notification <-- this should trigger something in your code. Do you have didReceiveNotificationResponse implemented? Does that get called? Or does your didFinishLaunching get launched with a remoteNotification key? How about your application(_:didReceiveRemoteNotification:fetchCompletionHandler:) does that get called?
I am working on a project where we are using Firebase Cloud Messaging for push notifications. The following JSON is currently being produced by the backend API and sent to FCM:
{
"priority": "normal",
"delay_while_idle": true,
"dry_run": false,
"time_to_live": 3600,
"notification": {
"body_loc_key": "MyCustomNotificationId"
},
"data": {
// contains notification data
},
"registration_ids": [
]
}
This notification should be silent, meaning it should be only received when the iOS application is in the foreground, however sometimes on some devices this notification also finds its way to the iOS notification tray with the app being in the background as if it had parameters to be displayed there.
I have found out the body_loc_key attribute must be present to iOS devices, otherwise the notification won't ever hit the device, whether the application is in the foreground or background.
The problem occured on the following devices:
Apple iPhone 5,
Apple iPhone 6,
with the possibility of others being affected as well.
Is there a different configuration for the JSON sent to FCM you have used with a success, where the notifications are only being sent to the device when the application is in the foreground?
After fiddling with the FCM payload for sime time we have found out the problem was actually the body_loc_key attribute all along.
In order for a notification to be silent and still sent to an apple device, the payload must meet the following criteria:
priority must be set to normal,
content_available must be set to true,
notification attribute must contain data, but should it contain the body_loc_key attribute it must be set to an empty string - "".
Working payload examples:
// Example one
{
"priority": "normal",
"delay_while_idle": true,
"dry_run": false,
"time_to_live": 3600,
"content_available": true,
"notification": {
"body_loc_key": ""
},
"data": {
// contains notification data
},
"registration_ids": [
]
}
// Example two
// (note that body_loc_key has been replaced with badge)
{
"priority": "normal",
"delay_while_idle": true,
"dry_run": false,
"time_to_live": 3600,
"content_available": true,
"notification": {
"badge": 10
},
"data": {
// contains notification data
},
"registration_ids": [
]
}
Changing the body_loc_key to an empty string pretty much fixed the issue. On top of that we have also found out the following about other attributes of the notification attribute:
badge may be present and is processed, notification remains silent,
title_loc_key has no effect, notification remains silent,
body_loc_args has no effect, notification remains silent.
All three additions apply to scenario where the precedent criteria have been met (empty body_loc_key if/when present, etc.).
The reason why your notification is being sent as display-message and not as silent-message is because you are using the notification payload.
In particular you are using the body_loc_key.
You wrote that you read that body_loc_key is required to send silent-messages.
This is not true.
Can you please link the page where you found this?
Can someone help on how to get device token on ios using ionic only. I've managed to get device token using Xcode but is it possible to get device token using ionic only?
I need to to add the device token when the users log in the app
Try this
using this plugin
cordova plugin add phonegap-plugin-push --variable SENDER_ID="XXXXXXX"
after that adding this
in to ionicPlatform.ready
var push = PushNotification.init({
"android": {
"senderID": "SENDER-ID"
},
"ios": {"alert": "true", "badge": "true", "sound": "true"},
"windows": {}
});
push.on('registration', function(data) {
console.log("registration event");
//here is your registration id
console.log(data.registrationId);
});
I may be very late in answering your question, your answer is as below
Update your ionic to latest version i,e v2 and above.
Then create a project and add this plugin
cordova plugin add phonegap-plugin-push --variable
SENDER_ID="XXXXXXXXX
Next goto src/app/app.component.ts file and add this code after platform.ready().then(()
var push = Push.init({
android: {
senderID: "XXXXXXXXX"
},
ios: {
alert: "true",
badge: true,
sound: 'false'
},
windows: {}
});
push.on('registration', (data) => {
console.log(data.registrationId);
alert(data.registrationId.toString());
});
push.on('notification', (data) => {
console.log(data);
alert("Hi, Am a push notification");
});
Perform all the certification part according to apple guidelines(if
any problem please do comment).
Finally implement push notification server side either in java or php or ionic.io ! All the best...