Created
September 29, 2018 19:21
-
-
Save vialyx/f96ebd6382021aafc5459234e8e2b147 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
enum Shortcuts: String { | |
case refreshList = "com.vialyx.MVD.refresh_list" | |
var identifier: String { | |
return rawValue | |
} | |
var title: String { | |
switch self { | |
case .refreshList: | |
return "shortcuts.refresh_list".localized() | |
} | |
} | |
var notification: Notification.Name { | |
switch self { | |
case .refreshList: | |
return Notification.Name(identifier) | |
} | |
} | |
} | |
extension NSUserActivity { | |
static func with(_ shortcut: Shortcuts) -> NSUserActivity { | |
let activity = NSUserActivity(activityType: shortcut.rawValue) | |
activity.title = shortcut.title | |
activity.userInfo = ["speech" : shortcut.title] | |
activity.isEligibleForSearch = true | |
if #available(iOS 12.0, *) { | |
activity.isEligibleForPrediction = true | |
activity.persistentIdentifier = shortcut.identifier | |
} else { | |
// Fallback on earlier versions | |
} | |
return activity | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment