iOS 9~ Experiments - New API Components - Shortcut Quick Action API with 3DTouch.
-
= XCode 8.0
-
= Swift 3.
-
= iOS 9.0.
-
= 3DTouch Devices.
Tested on iOS 9.0, iOS 10 Simulators iPhone 6S, 6S Plus, 7.
this is the Xcode 8 / Swift updated project.
To run the example project, download or clone the repo.
/// Define quick actions type
enum QuickActionsType: String {
case First = "quickactions.domain.first"
case Second = "quickactions.domain.second"
case Third = "quickactions.domain.third"
}
- performActionForShortcutItem example
/// Calls - user selects a Home screen quick action for app
func application(application: UIApplication, performActionForShortcutItem shortcutItem: UIApplicationShortcutItem, completionHandler: (Bool) -> Void) {
// perform action for shortcut item selected
let handledShortCutItem = QuickActionsForItem(shortcutItem)
completionHandler(handledShortCutItem)
}
- didFinishLaunchingWithOptions example
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// set if app launched from shorcut with boolean
var appLaunchedFromShortCut = false
// check current shortcut item
if let currentShorcutItem = launchOptions?[UIApplicationLaunchOptionsShortcutItemKey] as? UIApplicationShortcutItem {
appLaunchedFromShortCut = true
QuickActionsForItem(currentShorcutItem)
}
// return false if app already launched
return !appLaunchedFromShortCut
}
- Build and Run!
- Switch to Home screen
- Simulator : SBShortcutMenuSimulator
- CAUTION! : make sure to uninstalled it after test!
- Devices : with future iPhone 6s and others 3DTouch devices!