Created
September 23, 2021 14:48
-
-
Save bergusman/968c74e0f6a15a25c4ea9e64107a9277 to your computer and use it in GitHub Desktop.
User Notifications
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
class UserNotificationCenterViewer { | |
class func viewDelivered() { | |
UNUserNotificationCenter.current().getDeliveredNotifications { notifications in | |
print("Delivered Notifications") | |
print("-----------------------") | |
for notification in notifications { | |
print("date:", notification.date) | |
print("identifier:", notification.request.identifier) | |
print("trigger:", notification.request.trigger ?? "nil") | |
let content = notification.request.content | |
print("title:", content.title) | |
print("subtitle:", content.subtitle) | |
print("body:", content.body) | |
print("sound:", content.sound as Any) | |
print("badge:", content.badge as Any) | |
print("threadIdentifier:", content.threadIdentifier) | |
print("categoryIdentifier:", content.categoryIdentifier) | |
print("targetContentIdentifier:", content.targetContentIdentifier ?? "nil") | |
print("launchImageName:", content.launchImageName) | |
print("summaryArgument:", content.summaryArgument) | |
print("summaryArgumentCount:", content.summaryArgumentCount) | |
print("attachments:", content.attachments) | |
print("userInfo:", content.userInfo) | |
print() | |
} | |
} | |
} | |
class func viewCategories() { | |
UNUserNotificationCenter.current().getNotificationCategories { categories in | |
print("Notification Categories") | |
print("-----------------------") | |
for category in categories { | |
print(category) | |
print("identifier:", category.identifier) | |
print("intentIdentifiers:", category.intentIdentifiers) | |
print("hiddenPreviewsBodyPlaceholder:", category.hiddenPreviewsBodyPlaceholder) | |
print("categorySummaryFormat:", category.categorySummaryFormat) | |
print("options:", category.options) | |
if category.options.contains(.customDismissAction) { | |
print(" - customDismissAction") | |
} | |
if category.options.contains(.allowInCarPlay) { | |
print(" - allowInCarPlay") | |
} | |
if category.options.contains(.hiddenPreviewsShowTitle) { | |
print(" - hiddenPreviewsShowTitle") | |
} | |
if category.options.contains(.hiddenPreviewsShowSubtitle) { | |
print(" - hiddenPreviewsShowSubtitle") | |
} | |
if category.options.contains(.allowAnnouncement) { | |
print(" - allowAnnouncement") | |
} | |
print("actions:", category.actions) | |
print() | |
} | |
} | |
} | |
class func viewSettings() { | |
UNUserNotificationCenter.current().getNotificationSettings { settings in | |
func takeAuthorizationStatus(_ status: UNAuthorizationStatus) -> String { | |
switch status { | |
case .authorized: return "authorized" | |
case .denied: return "denied" | |
case .notDetermined: return "notDetermined" | |
case .provisional: return "provisional" | |
case .ephemeral: return "ephemeral" | |
default: return "unknown" | |
} | |
} | |
func takeShowPreviewsSetting(_ setting: UNShowPreviewsSetting) -> String { | |
switch setting { | |
case .always: return "always" | |
case .never: return "never" | |
case .whenAuthenticated: return "whenAuthenticated" | |
default: return "unknown" | |
} | |
} | |
func takeSetting(_ setting: UNNotificationSetting) -> String { | |
switch setting { | |
case .disabled: return "disabled" | |
case .enabled: return "enabled" | |
case .notSupported: return "notSupported" | |
default: return "unknown" | |
} | |
} | |
func takeAlertStyle(_ style: UNAlertStyle) -> String { | |
switch style { | |
case .alert: return "alert" | |
case .banner: return "banner" | |
case .none: return "none" | |
default: return "unknown" | |
} | |
} | |
print("Notification Settings") | |
print("---------------------") | |
print("authorizationStatus:", takeAuthorizationStatus(settings.authorizationStatus)) | |
print("soundSetting:", takeSetting(settings.soundSetting)) | |
print("badgeSetting:", takeSetting(settings.badgeSetting)) | |
print("alertSetting:", takeSetting(settings.alertSetting)) | |
print("notificationCenterSetting:", takeSetting(settings.notificationCenterSetting)) | |
print("lockScreenSetting:", takeSetting(settings.lockScreenSetting)) | |
print("carPlaySetting:", takeSetting(settings.carPlaySetting)) | |
print("alertStyle:", takeAlertStyle(settings.alertStyle)) | |
print("showPreviewsSetting:", takeShowPreviewsSetting(settings.showPreviewsSetting)) | |
print("criticalAlertSetting:", takeSetting(settings.criticalAlertSetting)) | |
print("providesAppNotificationSettings:", settings.providesAppNotificationSettings) | |
print("announcementSetting:", takeSetting(settings.announcementSetting)) | |
print() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment