Notifications in iOS - ios

I have a requirement for an application, when it has multiple notifications and when the user clicks one of those, the rest of the notifications of the same app should still be visible in the notification centre. Normally what happens is those other notifications also get cleared. Is there a way that I can bypass this scenario?
Update - Is there a way that we can access received push notifications in the notification center?

Its done by iOS. Programmers have no control over it.
You can get the notification if the user click on the item in notification center and application is opening from it. Following is the code for it
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSDictionary *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
//your notification will be in the dictionary if application is opening from notification center
return YES;
}

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.

iOS - notifications (local / remote) just open the app, not showing alerts

My app receives all the notifications local and remote. And also working fine with showing Alerts.
But when i press Home button and remove app from app stack or from recent apps. And after that any notification come, my app informed me for notification in notification bar. And when i tapped the notification, this is just opening my app (not showing alert). [When app is in app Stack / recent apps and any notification arrives and after tapping on this will open the app and also show me alerts.]
Any one have solutions or faced problem like this.
Thank You
Try this code it will helps to you, you get notification info in didFinishLaunchingWithOptions
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UILocalNotification *localNotif =[launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];
if(localNotif) {
//get notification info
localNotif.userinfo
}
return YES;
}

Local Notifications with iOS 8

Local notification are working well in foreground. but I need to perform some background work when a notification banner displays. It is working well when I tap on the banner when local notifications appear.
Code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (notification)
{
NSLog(#"AppDelegate didFinishLaunchingWithOptions");
[self application:application didReceiveLocalNotification:notification];
}
return YES;
}
My problem is similar to this issue
I used code below to perform background task:
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
dispatch_async(dispatch_get_main_queue(), ^{
[[ReminderManger sharedMager] handleNotification:[[notification userInfo] objectForKey:#"reminderId"]];
});
}
There is no way to do that. Notifications are handled by iOS itself. If app would be handling this, there might be some way to get this figured out. I've been wasting my time over it but didn't succeed.
The only thing you can do is to get extended permission from iOS that your app need multi tasking in background. And then in background make your app become post local notifications, this will show banner whenever you want but you can't customize the banner. See Apple's line "An app that is running in the background may also schedule a local notification to inform the user of an incoming message, chat, or update." at this link
Now the thing is in background, you cant change your views, but parse data, and based on this you can make changes at time of launch.

iOS: Handling Remote (push) Notifications

I'm trying to handle all possible cases with remote notifications.
I'm ok when app in foreground - didReceiveRemoteNotification is called.
The problem is when app in background state, and I receive push notification.
Nothing is called.
how to let user know that he has new remote notification when app come back to foreground ?
The only way for you to intercept a push notification is when the user tap the notify in the notification center (or when slide the app icon from the lock screen).
In this case before the app go in foreground the didFinishLaunchingWithOptions method in the app delegate is called. You should use the NSDictionary launchOptions to determine if the app has been launched from notification center or by tapping the icon (the normal use)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSDictionary *pushDic = [launchOptions objectForKey:#"UIApplicationLaunchOptionsRemoteNotificationKey"];
if (pushDic != nil) {
NSLog(#"Notification");
}
else {
}
}
Just have a look into the programming guide:
If the action button is tapped (on a device running iOS), the system launches the application and the application calls its delegate’s application:didFinishLaunchingWithOptions: method (if implemented); it passes in the notification payload (for remote notifications) or the local-notification object (for local notifications).
Of course, if your app is in background, there will be nothing called...
If your app is not launched (not even suspended in background), the
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
will contain the notification payload (key UIApplicationLaunchOptionsRemoteNotificationKey):
NSDictionary *remoteNotification = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];

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