iOS 3D Touch

2017-01-20  本文已影响0人  海岸没有沙

这里不多废话,直接写代码!

首先我们需要在info.plist中添加一个如下图:

也就是我们按应用图标的时候会出现的三个选项。

然后在AppDelegate中写下面方法就行了 

- (void)application:(UIApplication*)application

performActionForShortcutItem:(UIApplicationShortcutItem*)shortcutItem

completionHandler:(void(^)(BOOLsucceeded))completionHandler{

//判断先前我们设置的唯一标识

if([shortcutItem.typeisEqualToString:@"UITouchText.share"]){

NSArray*arr =@[@"hello 3D Touch"];

UIActivityViewController*vc = [[UIActivityViewControlleralloc]initWithActivityItems:arrapplicationActivities:nil];

//设置当前的VC为rootVC

[self.window.rootViewControllerpresentViewController:vcanimated:YEScompletion:^{

}];

}

elseif([shortcutItem.typeisEqualToString:@"UITouchText.search"])

{

UIAlertView*alertView = [[UIAlertViewalloc]initWithTitle:@"温馨提示"message:@"好想你"delegate:nilcancelButtonTitle:@"cancle"otherButtonTitles:@"sure",nil];

[alertViewshow];

}

elseif([shortcutItem.typeisEqualToString:@"UITouchText.look"])

{

UIActionSheet*sheet = [[UIActionSheetalloc]initWithTitle:@"温馨提示"delegate:nilcancelButtonTitle:@"cancle"destructiveButtonTitle:@"删除"otherButtonTitles:@"更多",nil];

[sheetshowInView:self.window];

}

elseif([shortcutItem.typeisEqualToString:@"UITouchText.compose"])

{

NSLog(@"UITouchText.compose");

}

}

上一篇 下一篇

猜你喜欢

热点阅读