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功能, 大体介绍一 ...
随机推荐
- javascript中对象的深度克隆
记录一个常见的面试题,javascript中对象的深度克隆,转载自:http://www.2cto.com/kf/201409/332955.html 今天就聊一下一个常见的笔试.面试题,js中对象的 ...
- Oracle job定时器的执行时间间隔学习汇总
Oracle job 定时器的执行时间间隔也是定时器job 的关键设置,在这一设置上,开始还没掌握,总是不知道怎么写,现总结如下,其实主要是使用了TRUNC.NEXT_DAY .ADD_MONTH ...
- Android实现接口方式注册监听器
初学Android,新手大都倾向使用匿名类的方式注册监听器, 如下: public class MainActivity extends Activity { private Button but ...
- 读javascript高级程序设计09-BOM
一.window 1.在全局作用域中定义的变量和函数会被归在window对象. var a=1,b=2; function add(a,b){ return a+b; } console.log(wi ...
- Android开发--LinearLayout的应用
1.简介 LinearLayout为安卓三大常用布局中的线性布局.其中,线性布局又分为水平线性布局和垂直线性布局.视图如下所示:
- DbUtils常用API的使用 方便以后查阅
package com.lizhou.Test; import java.sql.SQLException; import java.util.List; import java.util.Map; ...
- 解决Ubuntu 下 vi编辑器不能使用方向键和退格键问题
转自:http://blog.csdn.net/sky101010ws/article/details/51012103 使用vi命令时,不能正常编辑文件,使用方向键时老是出现很多字母 这个问题主要是 ...
- PHP数据库页面增删查
1.用户操作页面 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ww ...
- BZOJ1880: [Sdoi2009]Elaxia的路线
题意:求最短路最长公共距离. 考虑每一条边,如果满足dis(s1,u)+len+dis(v,t1)==dis(s1,t1) && dis(s2,u)+len+dis(v,t2)==di ...
- Regsvr32.exe 用法
RegSvr32.exe 具有以下命令行选项: Regsvr32 [/u] [/n] [/i[:cmdline]] dllname /u - 取消注册服务器 /i - 调用 DllInstall,为 ...