美文网首页
iOS 3D Touch

iOS 3D Touch

作者: 海岸没有沙 | 来源:发表于2017-01-20 14:31 被阅读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");

    }

    }

    相关文章

      网友评论

          本文标题:iOS 3D Touch

          本文链接:https://www.haomeiwen.com/subject/uqgwbttx.html