How to know what's coming from push notification in iOS? - ios

I can't NSLog as simulator doesn't support push notification. How I can view the data coming from push notification and what's in that launchOption dictionary?

First of all you want real devices to check push notification.
There is one method to check content of push notification in ios
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NsLog("%#",userInfo);//In the userinfo you will get the content of push notification.
}
May be it will help you.

Related

iOS: Programmatically dismiss a notification that is displayed on lock screen?

Imagine this: A user sees a notification on their lock screen e.g. "your server is online". Then something changes e.g. the server goes offline. Can I programmatically remove that notification (dismiss it) from the background even after it has been displayed on the lock screen?
Yes you actually can do this, you typically see it in action in messenger apps or social networking apps, for example, in some messenger app that has a web version, if you receive a message and you read it from the web but you already have received the push on your iOS app, when this happens you must send another push without display message, but a tag with value that indicates whatever you want:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
if([[userInfo objectForKey:#"reset"] boolValue]){
[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
}
}
This is a silent push notification.

Remote Notification not adding in iPhone Notification Center in iOS 9

My notification working when app is Active.
I have enable background mode 1.Background Fetch. 2. Remote Notification
App Delegate look like
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
//rest of code
completionHandler(UIBackgroundFetchResultNewData);
}
Also, Paylaod look like
{
aps={ "content-available"=1;
message="asdf"
};
}
Notification in app state as follows
Active= Working
Background= Received but not added in notification center i need to
manually click on app.(I can't see it in device notification center)
Closed: Not working (Expected to add in Notification center).
I tested by re-starting device,
What could be the issue?
Is it due to absence of "alert","sound" in payload?
Yes, you need an alert value, otherwise there's nothing to display in the Notification Center.
The Remote Notification Payload

objective c Push notification BackGround remove old one when receive new one in Notification center

I created a application. That receives push notifications from server.
This all works for me.
But the only thing is that i want that my old push notification in notification center will be removed when i receive a new one.
What do i need to do in this function
- (void)application:(UIApplication *)application didReceiveRemoteNotification: (NSDictionary *)userInfo {
This doesn't solve my problem
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
doesn't work
It is for Background(when you are home screen or locked your phone).
Or is it possible to replace your old push notification for new one

How can I defer handling a push notification in a running ios app?

If application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo is triggered in my running app, but I don't want to handle it right now, is it possible to leave it posted in the Notification Center so the user can swipe down later and click on it?
No, active apps get the push notification directly and the notification will not be added to the notification center.
You will have to handle it directly or store it your self for later use.

Remove single remote notification from Notification Center

my app receives remote notification from Apple server.
Is there a way to remove a single remote notification from notification center (the drop-down menu available from iOs 5.0+), when the user taps on it?
Thanks!
There is no way to remove a specific notification as of iOS SDK 5.0. The way to remove all the notifications from your app so they don't show in the Notification Center when the user opens the app from one of them, is to set the app badge to 0, like this:
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
EDIT: on iOS 8, SpringBoard seems to be automatically dismissing a notification when you tap on it on the Notification Center to open the app.
Here is a suggestion, though it does have its flaws, and I haven't tried it myself:
Push a silent notification (contentAvailable:true), don't include a "alert" inside the push, place the alert text in a custom property of the push
Handle the incoming push and trigger a local notification, display it immediately
If the user clicks the local notification, use the [UIApplication cancelLocalNotification:] which should remove the notification from the notification center.
When you call the method:
[application cancelAllLocalNotifications];
inside the AppDelegate methods:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
and
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
All Local and Push Notifications will be remove on that for the particular app.

Resources