Skip to content

Instantly share code, notes, and snippets.

@johnludwigm
johnludwigm / CustomNotifications.swift
Created December 19, 2017 17:11
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).
@johnludwigm
johnludwigm / NotificationsAppDelegate.swift
Last active December 19, 2017 17:31
Allows iOS app to present local notifications while app is in foreground.
import UIKit
import UserNotifications
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
let notificationDelegate = CustomNotifications()
@johnludwigm
johnludwigm / AppDelegate.swift
Last active December 18, 2017 23:32
Regular AppDelegate
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.