Created
December 19, 2017 17:11
-
-
Save johnludwigm/c241bd6aef820d3d1de0b60d1eafb1ee to your computer and use it in GitHub Desktop.
Custom notifications delegate class for iOS development.
This file contains hidden or 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
import Foundation | |
import UserNotifications | |
class CustomNotificationDelegate: NSObject, UNUserNotificationCenterDelegate { | |
func userNotificationCenter(_ center: UNUserNotificationCenter, | |
willPresent notification: UNNotification, | |
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { | |
//Play sound, show alert (will occur if enabled by user AND scheduled in the notification request). | |
completionHandler([.alert, .sound]) | |
} | |
func userNotificationCenter(_ center: UNUserNotificationCenter, | |
didReceive response: UNNotificationResponse, | |
withCompletionHandler completionHandler: @escaping () -> Void) { | |
//Note that any categories you may wish to use will need to be handled in the completionHandler. | |
completionHandler() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment