Badge number not updating in UrbanAirShip - iphone

I am new to iOS.
I am using urban Airship for push notification.
Now when I send notification for the first time I got badge 1.
But when I again send the notification it still reamins to +1 though
I send notification with +1 badge.
I use
[[UAPush shared] setAutobadgeEnabled:YES];
[[UAPush shared] resetBadge];
in didFinishLaunchingWithOptions method.
Thanks

Push notifications always set the badge number to the value sent. There is no incrementing. If you send no value, then the badge mains unchanged on what it was previously. If you send 0, then the badge is removed.
Looking at the documentation I find that you have to supply the correct value for the badge parameter: supported are auto,increment and decrement. Those take the recent value from UA's database and modify it according to the keyword.
This is something you need to do in the push notification JSON dictionary.
PS: you should check out our app Airship Commander when it gets approved by Apple. This has a stepper control to leave, erase or set the badge number: http://www.cocoanetics.com/2012/12/airship-commander-1-0/

Related

iOS: Notification Badge Number does not reset

I want to reset the notification badge number whenever the app is opened. This works perfectly fine calling
application.applicationIconBadgeNumber = 0
UNUserNotificationCenter.current().removeAllDeliveredNotifications()
However, when I one ore more new notifications come in, the icon badge number again goes to 42 no matter how many notifications come in.
Does anyone know how to fix this?
You can follow one of the following for achieving this,
You can store notifications received in your database and when user opens app, you can get the count of unread notifications and update the count.
If you are targeting single users then, you can get the delivery of Push notifications using https://stackoverflow.com/a/50044201/5084797 and then when the notification is opened you can pass notification Open event to server. So the next time the server sends push notification, they can just check for the difference in Deliver and Open and send that count in badge. If user has cleared all notifications from Notification centre without opening them. In that case as soon as App opens you need to update that at server, Else you might be getting wrong count from server.

UIApplication registerForRemoteNotificationTypes: not respecting absence of UIRemoteNotificationTypeBadge

I'm calling UIApplication's registerForRemoteNotificationTypes: specifying only UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound. I am not specifying UIRemoteNotificationTypeBadge.
My app's server, however, is sending an APNS notification payload that includes a "badge" key having a value of "1".
When the notification is received, my app's icon is badged with a red circled "1".
Even though the payload includes badge information, my expectation is that because I do not specify UIRemoteNotificationTypeBadge, that iOS would not show a badge on my app's icon.
Could someone explain what the expected behavior is?
Thanks.
-Allan
You are correct that the OS shouldn't be displaying the badge unless your app has registered to receive that notification.
From the docs for registerForRemoteNotificationTypes:
iOS does not display or play notification types specified in the notification payload that are not one of the requested ones. For example, if alert messages are not one of the accepted notification types, iOS does not display an alert even if one is specified in the notification payload.
To find out what the application’s current notification types are, call the enabledRemoteNotificationTypes method.
Are you possibly using a token from a previous registration where the badge was specified?
Your payload server may be using a token which has the badge type registered.

APNS and iOS 5 Notification Center

I'm using iOS 5 and Push Notifications (with notification bar).
I have received 5 notifications that are available in the notification center. When I tap on any of them, the app launches and I am presented with the payload dictionary in application:didFinishLaunchingWithOptions. After this point, all other notifications related to the app disappear from the notification center.
I want to know if I can achieve any of the following
I can let the unread (untapped) notifications be available in the notification list (for later viewing).
I can get the payload(s) of all unread notifications in application:didFinishLaunchingWithOptions when I tap any one unread notification.
For notifications to remain in Notification Center after your app has been launched from one of them, their payload needs to include a badge number, and your app needs to refrain from setting its badge counter to 0 until it wants to clear all of its notifications from the Notification Center.
There is no way to access the notification payload of APNS messages other than the one your app was launched from. The general best practice if you need that data—particularly considering that APNS delivery is not guaranteed—is to retrieve it separately from your own web service.

any option to know if apple app get the push notification?

I build xcode app that get push notification, the main problem is that the push notification is very critical for me.
so I want to check if the push notification is delivered to the device with the app installed, I understand that if the iphone dosn't have internet connecction / 3G the push notification is not getting to the device.
how can I check if the device get the notification or not?
how can I check if the APNS successful to deliver the push notification?
I want to send sms if the push notification is not deliver to the device so I think about the idea to get the notification event when it's open by the push notification, and to send request to my server so i can know if the push notification is successful deliver or not. the main problem is that the user need to open the app every time he get the notification and in the night it's a problem. so this option is not good for me.
I check the feedback server push notification but i don't find any info that I can get if the push notification is delivered or not
any idea??
With iOS7 you have a new method called
application:didReceiveRemoteNotification:fetchCompletionHandler:
which you probably could use for your task. From Apple's Docs:
Implement this method if your app supports the remote-notification background mode.
...
When a push notification arrives, the system displays the notification to the user and
launches the app in the background (if needed) so that it can call this method. Use this
method to download any data related to the push notification. When your method is done,
call the block in the handler parameter.
Unlike the application:didReceiveRemoteNotification: method, which is called only when
your app is running, the system calls this method regardless of the state of your app.
The short answer, you can't, since APNS is one way. However, since an app can execute arbitrary code upon receipt of a notification, you can use this to say, send an http request to your own server when the notification is recieved.
There are any number of reason why push notifications might not get delivered to your user, or might not be delivered in a timely manner. Apple does not provide any mechanism for you to query the status of a push notification that you have sent.
If your app is currently running on the user's device and the user is accepting notifications for your app, you can implement the following method in your app delegate. It would be called whenever a push notification is received and in this method you could send a request back to your server to indicate the message was received. However this will only work while the user is running your app.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
In general though, it sounds like you'e relying on push notifications for something you shouldn't. From Apple's Local and Push Notification Programming Guide:
Important Because delivery is not guaranteed, you should not depend on
the remote-notifications facility for delivering critical data to an
application via the payload. And never include sensitive data in the
payload. You should use it only to notify the user that new data is
available.
There is no way to find out whether the notification was delivered to the device or no. APNS is a one way service. If there is no internet connection on the device then the APNS server will hold the last notification for some period of time which is no specified by Apple. If a new notification is sent to APNS for delivery then the old notification data is lost and replaced by the new data if its undelivered. If the notification is delivered then also the old notification data is deleted on the APNS server.
Please go through the following link : Apple Push Notification
Hope this helps you...........
If you are using JAVAPNS to send the APNS notification, you can use the below:
List<PushedNotification> notifications =
Push.combined("alert", badge, "default", "cert.p12", "certpassword", true, deviceToken);
for (PushedNotification notification : notifications) {
if (notification.isSuccessful()) {
//Push is successful. Do your thing...
}
else {
//Push is not successful. Do your thing...
}
}

What happens when user does not respond to Push Notification?

Lets assume a user receives a notification. The user did not respond to notification. what happens? will it automatically get closed? if yes, what is the duration for the expiry of notification on the device? Thanks in advance.
The notification will not automatically get closed, but if another one comes in—be it a text message, a voicemail, or even a notification from another app—then your notification will effectively vanish. If the notification payload includes a badge number for your app, then that will get updated; aside from that, though, once another notification supersedes it, yours is gone.
To your app the behaviour will be the same as if he tapped the close button.
If the user doesn't respond, your app will never know. The push message will remain on the screen until the phone is unlocked or some other message is received (SMS or other push notification)