Alternative to UserNotificationCenterDelegate’s willPresent when app is in background

For iOS 10 local notifications your out of luck. For iOS 10 remote notifications —regardless of user interaction you can receive callbacks using application(_:didReceiveRemoteNotification:fetchCompletionHandler:). (It’s kind of confusing that they deprecated most notification related methods but not this one) Callback for when app is in foreground and you’re about to show the notification: func userNotificationCenter(_ … Read more

Add Local Notification in iOS 10 – Swift 3

You need to register for Notification…I tried and this works. func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Override point for customization after application launch. let center = UNUserNotificationCenter.current() center.requestAuthorization([.alert, .sound]) { (granted, error) in // Enable or disable features based on authorization. } return true } Edit: You dont need … Read more

Getting local notifications to show while app is in foreground Swift 3

There is a delegate method to display the notification when the app is open in iOS 10. You have to implement this in order to get the rich notifications working when the app is open. extension ViewController: UNUserNotificationCenterDelegate { //for displaying notification when app is in foreground func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler … Read more

Registering for Push Notifications in Xcode 8/Swift 3.0?

Import the UserNotifications framework and add the UNUserNotificationCenterDelegate in AppDelegate.swift Request user permission func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { let center = UNUserNotificationCenter.current() center.requestAuthorization(options:[.badge, .alert, .sound]) { (granted, error) in // Enable or disable features based on authorization. } application.registerForRemoteNotifications() return true } Getting device token func application(_ application: UIApplication, … Read more