关于3D touch的体验,要求在iOS9下,真机测试。
判断当前设备是否支持3D touch,可以使用以下方法
if(self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable)
返回为yes(支持),no(不支持)
这里需要我们设置工程的info.plist文件的配置
先添加一个UIApplicationShortcutItems选项,数组类型
继续添加一个item0选项,字典类型。(可以添加多个以此类推)
[key]UIApplicationShortcutItems[/key]
[array]
[dict]
[key]UIApplicationShortcutItemIconType[/key]
[string]UIApplicationShortcutIconTypeShare[/string]
[key]UIApplicationShortcutItemTitle[/key]
[string]Share[/string]
[key]UIApplicationShortcutItemType[/key]
[string]TouchText.share[/string]
[/dict]
[/array]
UIApplicationShortcutItemIconType:对应的是系统下的图标类型,如:UIApplicationShortcutIconTypeShare、UIApplicationShortcutIconTypeSearch等
//如果我们想使用我们自己自定义的图标的话,就需要讲 UIApplicationShortcutItemIconType这个选项更改为UIApplicationShortcutItemIconFile
UIApplicationShortcutItemIconFile:这个选项是使用我们自己的图标文件,如:icon.png(中文图标名为测试)
UIApplicationShortcutItemTitle:要显示的主标题,如:Share这个就是自定一的主标题。
UIApplicationShortcutItemSubtitle:要显示的副标题,在主标题下方,如:subtitle。(可自行选择添加)
UIApplicationShortcutItemType:用于区分点击的是那个item,如:TouchText.share 请使用唯一标识,不要跟其他item的标识重复。
UIApplicationShortcutItemUserInfo :还可以添加一个用户信息的字典选项,传入你所需要的信息
//通过item的唯一标识可以判断点击的哪一个item,并进行相应的逻辑操作。
-(void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler{
//如果传入的有userInfo,可以在这里获取shortcutItem.userInfo
if ([shortcutItem.type isEqualToString:@"TouchText.share"]) {
NSArray *arr = @[@"hello 3D touch"];
UIActivityViewController *actVC = [[UIActivityViewController alloc]initWithActivityItems:arr applicationActivities:nil];
[self.window.rootViewController presentViewController:actVC animated:YES completion:^{
}];
}
}