Skip to content

Instantly share code, notes, and snippets.

@johnludwigm
Created December 19, 2017 17:11
Show Gist options
  • Save johnludwigm/c241bd6aef820d3d1de0b60d1eafb1ee to your computer and use it in GitHub Desktop.
Save johnludwigm/c241bd6aef820d3d1de0b60d1eafb1ee to your computer and use it in GitHub Desktop.
Custom notifications delegate class for iOS development.
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