3D Touch集成过程整理
1、集成App图标按压快速打开某个功能
在AppDelegate.m中加入以下三个东西
在启动方法里加入3D Touch菜单
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...... //3D Touch iOS9以上才支持
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0){ //创建3D Touch菜单
[self createItem]; //启动的时候判断是不是点击3D Touch菜单进来的
UIApplicationShortcutItem *shortcutItem = [launchOptions valueForKey:UIApplicationLaunchOptionsShortcutItemKey];
if (shortcutItem)
{
[SaveData setValueToSettingWithName:@"ShortcutItemType" value:shortcutItem.type];
//NSLog(@"We've launched from shortcut item: %@", shortcutItem.localizedTitle);
}
else
{
//NSLog(@"We've launched properly.");
} } return YES;
}
#pragma mark - 创建3D Touch菜单
-(void)createItem{ //给App图标添加3D Touch菜单
//签到
//菜单图标
UIApplicationShortcutIcon *iconSignin = [UIApplicationShortcutIcon iconWithTemplateImageName:@"3dtouch_signin"];
//菜单文字
UIMutableApplicationShortcutItem *itemSignin = [[UIMutableApplicationShortcutItem alloc] initWithType:@"" localizedTitle:@"签到"];
//绑定信息到指定菜单
itemSignin.icon = iconSignin; //记体重
//菜单图标
UIApplicationShortcutIcon *iconWeight = [UIApplicationShortcutIcon iconWithTemplateImageName:@"3dtouch_weight"];
//菜单文字
UIMutableApplicationShortcutItem *itemWeight = [[UIMutableApplicationShortcutItem alloc] initWithType:@"" localizedTitle:@"记体重"];
//绑定信息到指定菜单
itemWeight.icon = iconWeight; //记录饮食运动
//菜单图标
UIApplicationShortcutIcon *iconFood = [UIApplicationShortcutIcon iconWithTemplateImageName:@"3dtouch_food"];
//菜单文字
UIMutableApplicationShortcutItem *itemFood = [[UIMutableApplicationShortcutItem alloc] initWithType:@"" localizedTitle:@"记录饮食运动"];
//绑定信息到指定菜单
itemFood.icon = iconFood; //发动态
//菜单图标
UIApplicationShortcutIcon *iconWeibo = [UIApplicationShortcutIcon iconWithTemplateImageName:@"3dtouch_weibo"];
//菜单文字
UIMutableApplicationShortcutItem *itemWeibo = [[UIMutableApplicationShortcutItem alloc] initWithType:@"" localizedTitle:@"发动态"];
//绑定信息到指定菜单
itemWeibo.icon = iconWeibo; //绑定到App icon
NSArray *items = [NSArray arrayWithObjects:itemWeibo, itemFood, itemWeight, itemSignin, nil];
[UIApplication sharedApplication].shortcutItems = [NSArray arrayWithArray:items]; }
#pragma mark - 桌面图标3DTouch按压后菜单的事件 - (void)application:(UIApplication *)application performActionForShortcutItem:(nonnull UIApplicationShortcutItem *)shortcutItem completionHandler:(nonnull void (^)(BOOL))completionHandler{ if ([SaveData getValueFromSettingWithName:LOGIN_TICKET]) {
if ([self.window.rootViewController isKindOfClass:NSClassFromString(@"RootTabBarController")])
{
//NSLog(@"有TabBar");
RootTabBarController *tabBar = (RootTabBarController *)self.window.rootViewController;
MLNavigationController *nav = (MLNavigationController *)tabBar.selectedViewController; //签到
if ([shortcutItem.type isEqualToString:@""]) { DFPointsMallViewController *newView = [[DFPointsMallViewController alloc]init];
newView.title = @"积分商城";
newView.hidesBottomBarWhenPushed = YES;
[nav pushViewController:newView animated:NO]; } //记体重
if ([shortcutItem.type isEqualToString:@""]) { RenwuRecordWeightViewController *newView = [[RenwuRecordWeightViewController alloc]init];
newView.title = @"记录体重";
newView.hidesBottomBarWhenPushed = YES;
[nav pushViewController:newView animated:NO]; } //记录饮食运动
if ([shortcutItem.type isEqualToString:@""]) { CalorieCalculatorViewController *newView = [[CalorieCalculatorViewController alloc]init];
newView.title = @"记录饮食运动";
newView.hidesBottomBarWhenPushed = YES;
[nav pushViewController:newView animated:NO]; } //发动态
if ([shortcutItem.type isEqualToString:@""]) { QuanziPubViewController *newView = [[QuanziPubViewController alloc]init];
newView.title = @"发动态";
MLNavigationController *mlNav = [[MLNavigationController alloc]initWithRootViewController:newView];
[nav presentViewController:mlNav animated:YES completion:nil]; } }
} }
注意:点击应用图标的快速入口进入app时,如果app在后台运行,则会调用后面的回调方法。如果是新打开app,参数则会传入到启动方法的launchOptions里,就和通知类似。
我这里如果点击是新打开app的话,我是先把数据先记录到本地,等进入到首页后再进行处理,处理好后再销毁记录在本地的数据。
方法如下:
//快速进入
if ([SaveData getValueFromSettingWithName:@"ShortcutItemType"]) {
NSString *shortcutItemType = [SaveData getValueFromSettingWithName:@"ShortcutItemType"]; //签到
if ([shortcutItemType isEqualToString:@""]) { DFPointsMallViewController *newView = [[DFPointsMallViewController alloc]init];
newView.title = @"积分商城";
newView.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:newView animated:NO]; } //记体重
if ([shortcutItemType isEqualToString:@""]) { RenwuRecordWeightViewController *newView = [[RenwuRecordWeightViewController alloc]init];
newView.title = @"记录体重";
newView.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:newView animated:NO]; } //记录饮食运动
if ([shortcutItemType isEqualToString:@""]) { CalorieCalculatorViewController *newView = [[CalorieCalculatorViewController alloc]init];
newView.title = @"记录饮食运动";
newView.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:newView animated:NO]; } //发动态
if ([shortcutItemType isEqualToString:@""]) { QuanziPubViewController *newView = [[QuanziPubViewController alloc]init];
newView.title = @"发动态";
MLNavigationController *mlNav = [[MLNavigationController alloc]initWithRootViewController:newView];
[self.navigationController presentViewController:mlNav animated:YES completion:nil]; } [SaveData removeValueFromSettingWithName:@"ShortcutItemType"]; }
下面这个是把数据记录到本地的方法,写下吧以免时间长忘记了
+(id)getValueFromSettingWithName:(NSString *)name{
//NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSUserDefaults *defaults = [[NSUserDefaults alloc]initWithSuiteName:@"group.fitmissSharedDefaults"];
id value = [defaults objectForKey:name];
return value;
} +(void)setValueToSettingWithName:(NSString *)name value:(id)value{
//NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSUserDefaults *defaults = [[NSUserDefaults alloc]initWithSuiteName:@"group.fitmissSharedDefaults"];
[defaults setObject:value forKey:name];
[defaults synchronize];
} +(void)removeValueFromSettingWithName:(NSString *)name{
//NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSUserDefaults *defaults = [[NSUserDefaults alloc]initWithSuiteName:@"group.fitmissSharedDefaults"];
[defaults removeObjectForKey:name];
[defaults synchronize];
}
group.fitmissSharedDefaults是在开发者中心里开启的分组,不用这个,用引掉的那个也行的。
3D Touch集成过程整理的更多相关文章
- iOS- 指压即达,如何集成iOS9里的3D Touch
1.前言 随着6S的到来,3DTouch被各大热门APP迅速普及,博主亲自体验后,发现使用便捷性大幅提高,随后自己照着文档,写了个Demo出来,分享给大家,希望能对有需要的朋友提供有一些帮助. 2 ...
- 初学3D Touch
引言 With iOS 9, new iPhone models add a third dimension to the user interface. A user can now press y ...
- 3D touch在Unity3D中的使用
0.开篇: 3D touch随着iOS9发布,它并不是一个单独的技术,而是可以分为pressure sensitivity.quick action以及peek&pop.在官方的介绍中提到可以 ...
- Swift 玩转 3D Touch 之 Peek & Pop
什么是3D Touch 3D Touch 是iOS9之后专为 iPhone6s 机型加入的新特性,这一新技术移植于 Mac Book 上的 ForceTouch 更准确地说应该是 ForceTouch ...
- 3D Touch ? 木有6s,也阔以玩!!!
3D Touch 之 Peek & Pop 3D Touch 是iOS9之后专为 iPhone6s 机型加入的新特性,这一新技术移植于 Mac Book 上的 ForceTouch 更准确地说 ...
- 【iOS】3D Touch
文章内容来源于Apple的开发者文档:https://developer.apple.com/library/content/documentation/UserExperience/Conceptu ...
- 3D touch 的 应用 --备用
在iPhone 6s和iPhone 6s Plus中Apple引入了3D Touch技术.3D Touch的触控技术,被苹果称为新一代多点触控技术.其实,就是此前在Apple Watch上采用的For ...
- iOS 3D Touch功能 3 -备
新的触摸体验——iOS9的3D Touch 一.引言 二.在模拟器上学习和测试3D Touch 附.SBShortcutMenuSimulator的安装和使用 三.3D Touch的主要应用 四.3D ...
- iOS 9之3D Touch
金田 北京时间9月10日凌晨, Apple在美国旧金山比尔格拉汉姆公民大礼堂(Bill Graham Civic Auditorium)召开新品发布会.本次着重介绍了3D Touch功能, 大体介绍一 ...
随机推荐
- 如何设置WebViewer的参数栏显示状态
当为用户提供数据过滤功能时,需要为报表添加参数,而很多应用场景下,在初次展现报表时就为报表会展现全部的数据,然后再通过参数供用户选择,从而实现数据过滤,而一旦为参数设置默认值,参数面板就会自动隐藏.导 ...
- 20169212《Linux内核原理与分析》第一周作业
实验 使用touch创建文件: man手册的内容很多,涉及了Linux使用过程中的方方面面,为了便于查找,是做了分册(分区段)处理的,在Research UNIX.BSD.OS X和Linux中,手册 ...
- 解决Centos7安装后无法联网的问题
1.进入目录/etc/sysconfig/network-scripts/ $ cd /etc/sysconfig/network-scripts/ 2.找到编辑ifcfg-enoxxxx文件,后面的 ...
- HTML5 WebSocket 实时推送信息测试demo
测试一下HTML5的websocket功能,实现了客户端→服务器实时推送信息到客户端,包括推送图片: websocket实现MessageInbound类 onTextMessage()/onBina ...
- HTTP-Session工作机制
HTTP-Session将HTTP这种无状态协议通过session来保存状态.然而session通过记录服务器生成编号来标识协议,从而服务器就可以识别协议的状态. session保存服务器端, co ...
- 获取LocationProvider
Android的定位信息由LocationProvider对象来提供,该对象代表一个抽象的定位组件.在开始编程之前,需要先获得LocationProvider对象. 一.获取所有可用的Location ...
- 初识selendroid
Testerhome社区的lihuazhang对selendroid官网的部分内容进行了翻译和讲解. 以下内容均摘自lihuazhang.感谢lihuazhang的讲解.原文地址:https://gi ...
- CodeForces 686B-Little Robber Girl's Zoo
题目: 有n头数量的动物,开始它们站在一排,它们之间有高度差,所以需要将它们进行交换使得最终形成一个不减的序列,求它们交换的区间.交换的规则:一段区间[l, r]将l与l+1.l+2与l+3..... ...
- Jenkins 2.26 发布,可扩展的持续集成引擎
Jenkins 2.26 发布了.Jenkins 主要用于持续.自动地构建/测试软件项目,如CruiseControl与DamageControl,监控一些定时执行的任务.更新内容: Allow Co ...
- 配置ConvenientBanner时出现的问题
ConvenientBanner: compile 'com.bigkoo:convenientbanner:2.0.5' 找不到依赖库 classpath 'com.jfrog.bintray.gr ...