Created
April 2, 2019 09:10
-
-
Save quangDecember/15b4f552ead2d35543bb53ed09355216 to your computer and use it in GitHub Desktop.
minimalist version of handle notification actions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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