iOS 10 Push Notification Tap Handler - ios

I am implementing Push Notifications the iOS 10 way and not able to figure out how would I intercept user's tap on the notification banner. None of the delegate call back gets called when user tap on the banner both in background and foreground mode. This looks more of an API issue in iOS SDK itself.
Anyone experienced the same and have a work around? Please let me know.

Ok, below delegate call back gets called when user tap on the notification. I had implemented specific actions on the notification banner and was putting a check on those action identifiers and completely missed the user tap :).
- (void)userNotificationCenter:(UNUserNotificationCenter *)iCenter didReceiveNotificationResponse:(UNNotificationResponse *)iResponse withCompletionHandler:(void(^)())iCompletionHandler

Related

iOS when receive a remote notification can we know it and do something?

There is several situations when receiving a remote notification:
app is not launched at all
app is foreground
app is background
what I am looking for is that user haven't click the notification to launch or active the app. can we catch the receiving and do some thing in such three situation?
I know 2 is ok, how about 1 and 3, and how to do it? thx a lot.
somebody mentions widget or NotificationService? is it possible?
You can try adding a Notification Service Extension to your app.
iOS will launch your extension (NOT your app) in background when it receives a push notification. Obviously what you can do inside an extension is fairly limited.
There are two ways to be notified when your app moves to the background: implement the applicationWillResignActive() method in your app delegate, or register for the UIApplication.willResignActiveNotification notification anywhere in your app. This particular notification is sent as soon as your app loses focus, meaning that it's triggered when the user taps the home button once (to return to the home screen) or double taps the home button (to enter multi-tasking).

Swift iOS system notification dismiss calback

Question:
Is there a way to detect if you get a system notification and you swipe away the notification banner (e.g. the alarm that triggers a system notification)?
More practical example:
In your app, you are doing some stuff and suddenly you get a notification from another app. Instead of tapping on the notification, you swipe up the notification (you dismiss it that way). After doing that, I want to capture that in the app.
Why:
Currently, I have a bug in the app, so if I can capture this action, I would be able to fix this bug.
Thanks in advance!
When notification appears, the willResignActiveNotification won't get called, therefore willEnterForegroundNotification won't get called, too.
The best solution here is to catch incoming notification and show the custom view describing this notification instead of system one. Thus, you can detect all actions/timings you need.

Handling notification in the background before user taps on them - Swift 3

In swift 3, how can I handle a local notification while the app is in the background and before the user taps on the notification?
UserNotificationController.userNotificationCenter(_:willPresent:withCompletionHandler:) is only called when the user taps on the notification.
My goal is to create a local notification that displays a screen similar to an incoming call in which the user can swipe to pick up or hang up.
Thanks!
According to this SO question, it's simply not possible:
iOS Local Notification - Callback when in Background
Quoting part of the answer given in that link:
If your app was in the background or not running, and the user does
not tap the notification and summon your app, you will get nothing at
all and will have no way to know that the notification fired. This is
because notifications are not for your benefit but are a way of
sending a message to the user. (It sounds, from your question, as if
you may be misusing local notifications as a way of sending a message
to yourself. That is not what they are for.)

Swift UILocalNotification: Is it possible to fire an event when Notification is displayed?

So I know the didReceiveLocalNotification event is fired when a user selects an action on a Local Notification.
But, is an event fired prior to that when the notification is displayed as a banner or alert when the app is not active? And can that be accessed to do some background code?
I am looking for an answer in Swift if you can help.
No, local notifications do not and cannot awake the app when firing and the application is not active. The user must tap the notification, or perform a developer defined action on it before the app hears anything.
If you need your app to wake up, you need to use a remote notification with content available flag set.

Can I show a custom Local notification View or an Custom Alert view when app is in Background?

Actually I want to show a local notification in my app. But i want to show this notification with some custom design like ok and cancel button on it and image also. Alert view also can work but i am not sure if i can show it when app is in background Please suggest some solution.
Thanks In advance.
You can't change the view of Local Notification when it fires and when your app is in background, till in iOS 7. May be in iOS 8 you can do this.
Also if you want to use the UIAlertView to show the Notification, you can only show it when the app is in foreground.
You have to use this function in AppDelegate.m file to get the notification when app is in foreground.
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification

Resources