3D Touch 的实现

1.在

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

方法中实现添加和分享的入口,代码如下 :

- (BOOL)application:(UIApplication *)application  didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

UIApplicationShortcutIcon *firstItemIcon = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeAdd];

UIMutableApplicationShortcutItem *firstItem = [[UIMutableApplicationShortcutItem alloc]initWithType:@"First" localizedTitle:@"添加" localizedSubtitle:nil icon:firstItemIcon userInfo:nil];

UIApplicationShortcutIcon *secondItemIcon = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeShare];              UIMutableApplicationShortcutItem *secondItem = [[UIMutableApplicationShortcutItem alloc]initWithType:@"Second" localizedTitle:@"分享" localizedSubtitle:nil icon:secondItemIcon userInfo:nil];     application.shortcutItems = @[firstItem,secondItem];

return YES;

}

2.实现这个方法

-(void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler

在这个方法中处理添加和分享的事件,代码如下:

-(void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler{

if ([shortcutItem.type isEqual:@"add"])

{          NSLog(@"执行添加事件");

}else if(

[shortcutItem.type isEqual:@"share"]

){

NSLog(@"执行分享的操作 ");

}

}

二、通过模拟器进行调试  使用[SBShortcutMenuSimulator](

https://github.com/DeskConnect/SBShortcutMenuSimulator

)来配置模拟器,使模拟器支持3D Touch

在终端中按顺序输入以下命令:

1.git clone https://github.com/DeskConnect/SBShortcutMenuSimulator.git

2.cd SBShortcutMenuSimulator

3.make

然后打开刚才写好的程序 运行一下打开模拟器,再去终端中按顺序输入一下命令:

1.xcrun simctl spawn booted launchctl debug system/com.apple.SpringBoard

--environment DYLD_INSERT_LIBRARIES=$PWD/SBShortcutMenuSimulator.dylib

2.xcrun simctl spawn booted launchctl stop com.apple.SpringBoard

3.echo 'com.apple.mobilecal' | nc 127.0.0.1 8000

注意: 'com.apple.mobilecal' ''里边写的是自己项目的Bundle identifier. 这行命令就是要让模拟器显示出3D Touch,每次想要显示快速入口只要重复操作即可


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 1、在didFinishLaunchingWithOptions:添加以下代码 UIApplicationShor...
    呦嚯嚯嚯12138阅读 1,801评论 0 1
  • 1.简单的介绍一下3D Touch 3D Touch的触控技术,被苹果称为新一代多点触控技术。其实,就是此前在Ap...
    Camille_chen阅读 14,170评论 19 33
  • 专著:http://www.jianshu.com/p/3443a3b27b2d 1.简单的介绍一下3D Touc...
    violafa阅读 4,636评论 1 0
  • 3D Touch 概述: 从.Net转来也快有半年之多了,从小生到现在也算是经历了无所bug了,不过还是打到不了I...
    LitterL阅读 4,057评论 8 1
  • 3D Touch其实就是快速进入指定app界面的一种方式。下面和大家分享一下简单的实现1、静态标签静态标签是我们在...
    航彪彪阅读 10,542评论 27 5

友情链接更多精彩内容