3Dtouch方法
@UIApplicationMain
classAppDelegate:UIResponder,UIApplicationDelegate{
varwindow:UIWindow?
funcapplication(application:UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject:AnyObject]?) ->Bool{
// Override point for customization after application launch.
//添加icon 3d Touch
letfirstItemIcon:UIApplicationShortcutIcon=UIApplicationShortcutIcon(type: .Share)
letfirstItem =UIMutableApplicationShortcutItem(type:"1", localizedTitle:"分享", localizedSubtitle:nil, icon: firstItemIcon, userInfo:nil)
letfirstItemIcon1:UIApplicationShortcutIcon=UIApplicationShortcutIcon(type: .Compose)
letfirstItem1 =UIMutableApplicationShortcutItem(type:"2", localizedTitle:"编辑", localizedSubtitle:nil, icon: firstItemIcon1, userInfo:nil)
application.shortcutItems= [firstItem,firstItem1]
returntrue
}
/**
3D Touch跳转
- parameter application:application
- parameter shortcutItem:item
- parameter completionHandler: handler
*/
funcapplication(application:UIApplication, performActionForShortcutItem shortcutItem:UIApplicationShortcutItem, completionHandler: (Bool) ->Void) {
lethandledShortCutItem =handleShortCutItem(shortcutItem)
completionHandler(handledShortCutItem)
}
funchandleShortCutItem(shortcutItem:UIApplicationShortcutItem) ->Bool{
varhandled =false
ifshortcutItem.type=="1"{//分享
letrootNavigationViewController=window!.rootViewControlleras?UINavigationController
letrootViewController = rootNavigationViewController?.viewControllers.firstasUIViewController?
rootNavigationViewController?.popToRootViewControllerAnimated(false)
rootViewController?.performSegueWithIdentifier("toShare", sender:nil)
handled =true
}
ifshortcutItem.type=="2"{//编辑
letrootNavigationViewController =window!.rootViewControlleras?UINavigationController
letrootViewController = rootNavigationViewController?.viewControllers.firstasUIViewController?
rootNavigationViewController?.popToRootViewControllerAnimated(false)
rootViewController?.performSegueWithIdentifier("toCompose", sender:nil)
handled =true
}
returnhandled
}