IOS Push Notification count - ios

I need to display push notification count. when user launches the application by tapping application or from notification bar.
Example: application is in background and device received 10 notifications related to my app. we have to display notification count 10 within app.
I can achieve this by adding content-update key in notification payload. But I don't want to make change in notification payload.

Your backend need to send bagdes for this :- Eaxmple
{
"aps" : {
"alert" : "You got your emails.",
"badge" : 9,
"sound" : "bingbong.aiff"
},
"acme1" : "bar",
"acme2" : 42
}
and you can use this badges in your apps.

You can check how many notifications were received (assuming you are incrementing badges in your push notifications) by checking [UIApplication sharedApplication].applicationIconBadgeNumber.
This also assumed you reset the badge count each time they leave the app (standard practice), if for some reason you don't though, simply save [via NSUserDefaults] the current badge count in the willResignActive callback and check the delta when they return.

Related

In swift remote notification is there a way to display a different message in the banner other than the one received from server when app is killed?

If my payload from the server is
{ "aps" : { "alert" : "You got a mail";
"badge" : 0;
}
"user": { "name" : "Nicole" } }`
And It also gives me some other data about the name of user who sent it . Is there a way to display custom message in the format : "Nicole sent a mail" in the notification center or banner ?
It is possible since iOS 10 by creating a Notification Service Extension. You can check the documentation for its details. Also, here is a good tutorial from Avanderlee that explains how to add Notification Service Extension to you app.

Are Actionable notifications in iOS only local notifications or they can be sent from the server as well?

Are Actionable notifications in iOS only local notifications, or can they be sent from the server?
I'm interested in adding an actionable notification with two buttons in the app. I read the official documentation and I'm not clear if this type of notification can only be only local notification or if they can be sent from the server as well.
The linked documentation even gives an example of how to do it. So yes, you can create actionable notifications from remote (push) notifications. Just send along the category identifier in the aps dictionary of the notification payload as described in the docs:
{
“aps” : {
“category” : “MEETING_INVITATION”
“alert” : {
“title” : “Weekly Staff Meeting”
“body” : “Every Tuesday at 2pm”
},
},
“MEETING_ID” : “123456789”,
“USER_ID” : “ABCD1234”
}
And then it will show the actions associated to that category.

badge should be set before opening the app in IOS

When notification received on IOS device at that time the badge should be changed and Badge should be set before opening the app.
I check this onNotificationOpen() method. But when I tap on notification then it calls.
I use cordova-plugin-firebase.
Here is the link https://github.com/arnesson/cordova-plugin-firebase
But is there a method that calls when the notification received on IOS device?
$ionicPlatform.ready(function() {
if (typeof FirebasePlugin != 'undefined') {
window.FirebasePlugin.subscribe("notficationsubscribe");
// Below method calls when i tap on notifcation and sets the badge number
window.FirebasePlugin.onNotificationOpen(function(data) {
window.FirebasePlugin.setBadgeNumber(4);
}
}
}
Above FirebasePlugin.onNotificationOpen() method calls when I tap on notification and sets the badge number, but I want to set the badge when notification received.
Anyone have ideas? How can I achieve it?
Actually i set a logic for it.
1) I stored a badgeCounter value to database.
2) when i wants to send the notification at that time i retrieve it from database
var badge = badgeCounter // it is an integer value
var notification = {
'title': 'Stock available',
'body': 'Click here to more details...',
'sound': 'default',
'badge': badge
};
3) After tap or click on notification, i cleared the badge using below.
window.FirebasePlugin.setBadgeNumber(0);
4) And also in database i update the value to '0' (zero).
Thus, i solve it and it perfectly works for me.
You don't set this with code, it will set itself based on what your notification contains. You'll have to include "badge":1 (or whatever number) in the notification payload when you send it from your server (Firebase). I'm not sure how it works with firebase, but take a look at the documentation for remote notifications. Notice the "Badge"-key.

How to set sound for push notifications in ios objective c?

I am working on an app in which I have implemented Apple push notifications. When my app is in background state then I am able to receive push notifications without sound but when my app is in active state then I am able to get sound for notifications but not showing any banner for it.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateInactive)
{
AudioServicesPlaySystemSound(1007);
}
else {
AudioServicesPlaySystemSound(1007);
carPlateNo = [userInfo valueForKeyPath:#"aps.alert.loc-args"];
if(![carPlateNo isEqualToString:#"Return Message"])
{
[self receiveServices];
}
// Push Notification received in the background
}
}
Can anyone help on this?
You have to set sound in APNS Payload only, and add sound clip in XCode bundle.
Sample Payload
{
"aps" : {
"alert" : "You got your emails.",
"badge" : 9,
"sound" : "bingbong.aiff"
},
"acme1" : "bar",
"acme2" : 42
}
More Info
Try This :
when you send push notification, just add the name of sound in JSON payload. Example:
{
"aps" : {
"alert" : "your alert message here.",
"badge" : 1,
"sound" : "samplemusic.aiff"
}
}
Thats it! You don't have to do anything special in code of app.
iOS takes care of delivering notification to app when app is killed. iOS also takes care of showing the banner/alert depending on user settings and also plays the audio for the notification.
What you can do though is specify what audio to play in your notification payload
{
"aps" : {
"alert" : "You got your emails.",
"badge" : 9,
"sound" : "bingbong.aiff"
},
"acme1" : "bar",
"acme2" : 42
}
If you don't want default notification sound you can bundle your own audio file of format .aiff and ship it with app and specify the file name in your notification payload as shown above
refer : https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html
As far as
when my app is in active state then I am able to get sound for
notifications but not showing any banner for it
concerned, when your app is in foreground its your app's responsibility to show any custom banner/alert. System default banner/alert will not be displayed. You can use https://github.com/sandeeplearner/SBNotificationBar for the same :)
- When my app is in background state then I am able to receive push
notifications without sound
There must be one the following two issues
1.Sound key is not there or sending empty value for it in payload (Reference)
2.Your phone in silent mode
- my app is in active state then I am able to get sound for notifications but not showing any banner for it.
When Application is active app is responsible to handle what to do on push notification receive for more please refer this answer

iOS push notification not received when screen is locked

I am using parse for push notification. Once I receive remote notification I pass it to the local notification, but issue is when screen is locked didReceiveRemoteNotification does not hit. I don't receive any notification.
I am using iOS8
Here's my payload:
{
CommentId = "8082a532-2380-4af5-bb3f-d247cfca519b";
CommentTitle = test; action = "com.lelafe.one4communities.Notifications.NotificationActivity";
aps = { };
moduleIdentifier = 8;
nTitle = "Comment posted by someone";
postingID = "c57a3d27-cfe5-41e9-a311-98a9fd7749ad";
}
There is one more parameter that you need to pass to your payload i.e. content-available and set its value to 1. It needs to be passed in case we wish that our app should receive notifications in the background.
The official documentation of parse describes this parameter as follows:
+content-available: (iOS only) If you are a writing a Newsstand app, or an app using the Remote Notification Background Mode introduced in iOS7 (a.k.a. "Background Push"), set this value to 1 to trigger a background download.
The problem is your dictionary aps:
Try checking out Apple's Documentation about The Notification Payload
Also Quoting #mamills answer:
If there is no badge, no alert, and no sound specified in the
dictionary (for the "aps" key) then a default message will not appear
and it will be completely silent.
Look again at example 5 in the document you referenced. aps can be
empty, and you can specify whatever custom data you would like as they
do with the "acme2" key. The "acme2" data is an example of where your
server's "special" payload could reside within the JSON payload.

Resources