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功能, 大体介绍一 ...
随机推荐
- WIN7 java7 环境变量配置
1 首先要搞清楚,java可能安装了两个部分,一个叫JDK,一个叫jre.其中jre若已经安装了,那么在安装JDK的时候,就不要放在默认的C:\Program File\java\XXX目录.最好另起 ...
- <转>浏览器内核分类
浏览器的种类成千上百,但所基于的内核,却没有几个.目前主流的浏览器内核主要为以下四种: 一.Trident内核,代表产品Internet Explorer说起Trident,很多人都会感到陌生,但提起 ...
- Windows Store App 用户库文件夹操作
上面介绍了与用户库文件有关的操作,包括创建.读写等,下面将介绍与用户库文件夹相关的操作. 与文件操作一样,想要对用户库文件夹进行操作,需要首先获取用户库的相应位置,获取的方法上面已经介绍过了,这里不再 ...
- JDE Section设置默认不执行
此属性设置后,该Section仅能通过手动调用,默认不执行.
- 引入git flow分支管理
git flow是Vincent Driessen提出了一个分支管理的策略,非常值得借鉴.它可以使得版本库的演进保持简洁,主干清晰,各个分支各司其职.井井有条. 先看下Vincent Driessen ...
- sqlserver中创建包含事务的存储过程
什么是事务 事务时包含1条或多条语句的逻辑单元.事务中的语句是一个整体,要么一起提交,要么一起撤销.事务在提交前可以回滚,一旦提交就不能撤销修改了,是永久性的修改. 为什么使用事务 ...
- C++不用任何算术运算符实现整数加法
这本是careerup的一道题,看到了以后自己做了一下,主要的难点就是加法里面的进位.直接上代码: int add(int a, int b) { ; }; int first = a, second ...
- CSS中相对定位与绝对定位
看了几个讲解定位的博客,觉得还不错,分享之: 博客一:http://blog.sina.com.cn/s/blog_4bcf4a5e010008o0.html 文章中,主要需要参考的有两点: 1,相对 ...
- O_NONBLOCK on regular file
It seems that writes/reads to regular files can't not be made non-blocking. I found the following re ...
- innerHTML,innerText,outHTML,outText区别
<p><div id="div" style="background-color:#ff9966;border:1px #ff0000 dashed;& ...