TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Dec 2015 |
SPMSupports SPM | ✗ |
Maintained by Igor Matyushkin.
The main purpose of Protein
framework is to simplify work with 3D touch in iOS. Protein
is compatible with iOS 8.
Source
folder to your project.or
Protein
cocoapodTo use Protein
for managing shortcut items, you need to add list of items to Info.plist
file in your project. Example:
In this example, we will use two shortcut items. One will launch app with blue screen, and other one with orange screen.
When you have described structure in Info.plist
file, you need to register those items in Protein
engine. For this purpose, subclass your AppDelegate
from PTAppDelegate
class.
@UIApplicationMain
class AppDelegate: PTAppDelegate {
var window: UIWindow?
var mainViewController: UIViewController?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Register shortcut items
registerShortcutItemType("blue-screen") { (shortcutItem) -> Void in
self.mainViewController?.view.backgroundColor = .cyanColor()
}
registerShortcutItemType("orange-screen") { (shortcutItem) -> Void in
self.mainViewController?.view.backgroundColor = .orangeColor()
}
// Create window
let frameForWindow = UIScreen.mainScreen().bounds
window = UIWindow(frame: frameForWindow)
window!.backgroundColor = .whiteColor()
window!.makeKeyAndVisible()
// Switch to view controller
mainViewController = UIViewController()
let navigationController = UINavigationController(rootViewController: mainViewController!)
navigationController.navigationBarHidden = true
window!.rootViewController = navigationController
// Return result
return true
}
}
PTAppDelegate
contains method named registerShortcutItemType(_:, _:)
. This method registers handler block for particular type of shortcut item. This block will be called when user tapped shortcut item.
Note: if your project supports iOS 8, you need to wrap calls for registerShortcutItemType(_:, _:)
into special condition:
if #available(iOS 9, *) {
registerShortcutItemType("blue-screen") { (shortcutItem) -> Void in
self.mainViewController?.view.backgroundColor = .cyanColor()
}
registerShortcutItemType("orange-screen") { (shortcutItem) -> Void in
self.mainViewController?.view.backgroundColor = .orangeColor()
}
}
Also, for completeness, PTAppDelegate
provides developer with unregisterShortcutItemType(_:)
method. But, usually, there's no reason to call this method.
Protein
is available under the MIT license. See the LICENSE
file for more info.