Last active
July 28, 2018 19:44
-
-
Save SebastianOsinski/c324861ea024850980fd10f831159167 to your computer and use it in GitHub Desktop.
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
import UIKit | |
import UserNotifications | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
var window: UIWindow? | |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { | |
application.registerForRemoteNotifications() | |
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (status, error) in | |
print(status) | |
print(error) | |
} | |
return true | |
} | |
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { | |
let hexString = deviceToken.map { String(format: "%02hhx", $0) }.joined() | |
print(hexString) | |
} | |
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { | |
guard let idToDelete = userInfo["del-id"] as? String else { | |
completionHandler(.noData) | |
return | |
} | |
UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: [idToDelete]) | |
completionHandler(.noData) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment