Last active
April 5, 2017 14:35
-
-
Save youvalv/5f2053f928d74ac2d2f5c5aad2edb76d to your computer and use it in GitHub Desktop.
New iOS notifications category
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
@available(iOS 10.0, *) | |
private func getNewCategoryByIdentifier(identifier: String) -> UNNotificationCategory { | |
let tookAction = UNNotificationAction(identifier: kTookActionIdentifier, title: NSLocalizedString("Took", comment: "Took"), options: []) | |
let laterAction = UNNotificationAction(identifier: kLaterActionIdentifier, title: NSLocalizedString("Later", comment: "Took"), options: []) | |
return UNNotificationCategory(identifier: identifier, actions: [tookAction, laterAction], intentIdentifiers: [], options: []) | |
} | |
// For comparison, here is the old category usage | |
private func getCategoryByIdentifier(identifier: String) -> UIUserNotificationCategory { | |
let tookAction = UIMutableUserNotificationAction() | |
tookAction.activationMode = .background | |
tookAction.title = NSLocalizedString("Took", comment: "Took") | |
tookAction.isDestructive = false | |
tookAction.isAuthenticationRequired = false | |
tookAction.identifier = kTookActionIdentifier | |
tookAction.behavior = .default | |
let laterAction = UIMutableUserNotificationAction() | |
laterAction.activationMode = .background | |
laterAction.title = NSLocalizedString("Remind me later", comment: "Remind me later") | |
laterAction.isDestructive = false | |
laterAction.isAuthenticationRequired = false | |
laterAction.identifier = kLaterActionIdentifier | |
laterAction.behavior = .default | |
let actionCategory = UIMutableUserNotificationCategory() | |
actionCategory.identifier = identifier | |
actionCategory.setActions([tookAction, laterAction], for: .default) | |
return actionCategory | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment