Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save quangDecember/15b4f552ead2d35543bb53ed09355216 to your computer and use it in GitHub Desktop.
Save quangDecember/15b4f552ead2d35543bb53ed09355216 to your computer and use it in GitHub Desktop.
minimalist version of handle notification actions
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self
}
return true
}
}
@available (iOS 10.0, *)
extension AppDelegate : UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
LocalNotificationManager.init().handle(notification: response.notification, actionIdentifier: response.actionIdentifier)
completionHandler()
}
}
// handle notifications, can come from 3rd party framework
struct LocalNotificationManager {
@available(iOS 10.0, *)
func handle(notification: UNNotification, actionIdentifier: String) {
if notification.request.identifier == "UYLLocalNotification" && actionIdentifier == "ACCEPT_ACTION" {
// some custom actions
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment