-1

I'm really new to notifications and I tried many of the answers mentioned in other questions and I'm pretty much confused.

So here's the situation. I have an app that receives remote notifications. I managed to configure it using the didReceiveRemoteNotification to display the message it receives and when the notification is tapped, the user is taken to a specific viewController via the SWReveal library. This works well if the app is in background.

In foreground I was told I should use the willPresent notification and didReceive response methods for iOS 10. I managed to get the notification to show up if the app is in foreground but tapping the notification does nothing. I want to perform the same functionality I have in the didReceiveRemoteNotification.

I also need to add action buttons for some of the notifications I get (background and foreground) and I have no idea how I can handle that.

Any help would really be appreciated.

Jaydeep Vora
  • 6,085
  • 1
  • 22
  • 40
Tarek
  • 783
  • 10
  • 31
  • "same functionality I have in the didReceiveRemoteNotification" same meaning what? If you want to add actions to your notifications then see [here](https://stackoverflow.com/a/44867472/5175709). Make sure you see the WWDC video as well. It's really helpful. (Likely your question is a duplicate of that question, but still your question is unclear. Make an edit) – mfaani Sep 18 '17 at 14:11

2 Answers2

1

For Swift 3,iOS 10

See if you have set the delegate of UNUserNotificationCenter(i.e UNUserNotificationCenter.current().delegate = self) in your viewDidLoad

and then handle the tap of notification in

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {

     //Handle notification tap
  }
Dhruv
  • 72
  • 4
0

One solution you can do is have the remote notification actually be a silent notification and then on your app when it receives this silent notification you immediately schedule a local notification. Now that it's a local notificaiton instead of a remote one you can do whatever you need to do on the client side (app side) which makes it more flexible.

TNguyen
  • 1,041
  • 9
  • 24
  • Are local notifications flexible enough to allow me to customize what happens when the user taps the notification body and action buttons "SEPARATELY"? Because so far, the didReceive response handles both which ends up executing the whole code whether the user taps the action button or the notification's body. – Tarek Sep 27 '17 at 14:33