1

I already knew about this code which can be used before iOS 10:

func application(_ application: UIApplication, didReceive notification: UILocalNotification) {

}

However, it's depreciated so I just want to ask is there any method that is equivalent to the UserNotifications framework or I just have to get by with this warning?

Note that I want the app to do something when app is in the background or is terminated.

techcoderx
  • 602
  • 1
  • 7
  • 21

1 Answers1

3

The deprecated method was notifying delegate when the app received notification while in foreground. Now UNUserNotificationCenterDelegate does the same thing:

func userNotificationCenter(
    UNUserNotificationCenter, 
    willPresent: UNNotification, 
    withCompletionHandler: @escaping (UNNotificationPresentationOptions) -> Void
)

Called when a notification is delivered to a foreground app.

Documentation.

kelin
  • 11,323
  • 6
  • 67
  • 104
  • what about when app is terminated or in the background? – techcoderx Mar 06 '17 at 12:15
  • @TianXi, nothing. You can't rise your app with a notification. But you can handle notification actions, in this case the app will be running in the background. Also, I gave direct answer to your question, please, accept it. – kelin Mar 06 '17 at 12:24