. 3D . / .
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) {
(granted, error) in
print("Permission granted: \(granted)")
guard granted else { return }
let action = UNNotificationAction(identifier: "addToCal", title: "Zum Kalender hinzufügen", options: [])
let category = UNNotificationCategory(identifier: "NEW_SESSION", actions: [action], intentIdentifiers: [], options: [])
UNUserNotificationCenter.current().setNotificationCategories([category])
self.getNotificationSettings()
}
UNUserNotificationCenterDelegate .
@available(iOS 10, *)
extension AppDelegate : UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
if response.actionIdentifier == "addToCal" {
}
}
}
:
UNUserNotificationCenter.current().delegate = self
{
"aps" : {
"category" : "NEW_MESSAGE_CATEGORY",
"alert" : {
"body" : "Acme message received from Johnny Appleseed",
"title" : "Test",
},
"badge" : 3,
},
}