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集成过程整理的更多相关文章

  1. iOS- 指压即达,如何集成iOS9里的3D Touch

    1.前言   随着6S的到来,3DTouch被各大热门APP迅速普及,博主亲自体验后,发现使用便捷性大幅提高,随后自己照着文档,写了个Demo出来,分享给大家,希望能对有需要的朋友提供有一些帮助. 2 ...

  2. 初学3D Touch

    引言 With iOS 9, new iPhone models add a third dimension to the user interface. A user can now press y ...

  3. 3D touch在Unity3D中的使用

    0.开篇: 3D touch随着iOS9发布,它并不是一个单独的技术,而是可以分为pressure sensitivity.quick action以及peek&pop.在官方的介绍中提到可以 ...

  4. Swift 玩转 3D Touch 之 Peek & Pop

    什么是3D Touch 3D Touch 是iOS9之后专为 iPhone6s 机型加入的新特性,这一新技术移植于 Mac Book 上的 ForceTouch 更准确地说应该是 ForceTouch ...

  5. 3D Touch ? 木有6s,也阔以玩!!!

    3D Touch 之 Peek & Pop 3D Touch 是iOS9之后专为 iPhone6s 机型加入的新特性,这一新技术移植于 Mac Book 上的 ForceTouch 更准确地说 ...

  6. 【iOS】3D Touch

    文章内容来源于Apple的开发者文档:https://developer.apple.com/library/content/documentation/UserExperience/Conceptu ...

  7. 3D touch 的 应用 --备用

    在iPhone 6s和iPhone 6s Plus中Apple引入了3D Touch技术.3D Touch的触控技术,被苹果称为新一代多点触控技术.其实,就是此前在Apple Watch上采用的For ...

  8. iOS 3D Touch功能 3 -备

    新的触摸体验——iOS9的3D Touch 一.引言 二.在模拟器上学习和测试3D Touch 附.SBShortcutMenuSimulator的安装和使用 三.3D Touch的主要应用 四.3D ...

  9. iOS 9之3D Touch

    金田 北京时间9月10日凌晨, Apple在美国旧金山比尔格拉汉姆公民大礼堂(Bill Graham Civic Auditorium)召开新品发布会.本次着重介绍了3D Touch功能, 大体介绍一 ...

随机推荐

  1. NGUI Camera's raycast hit through the UI Layer issue

    Raycast into GUI?http://forum.unity3d.com/threads/raycast-into-gui.263397/ << ; Ray myray = UI ...

  2. python编程技巧2

    模块化 ---- 这是我们程序员梦寐以求的,通过模块化可以避免重复的制造轮子. 同时 模块让你能够有逻辑地组织你的Python代码段. 把相关的代码分配到一个 模块里能让你的代码更好用,更易懂. 模块 ...

  3. windows上安装numpy,scipy

    题外话:本来按照python官方的设计,可以直接使用easy_install或者pip在线安装各个组件,但是国内的网络你懂得!老老实实下载文件本地安装吧. 1.安装windows 的python 2, ...

  4. iOS开发UI篇—在UIImageView中添加按钮以及Tag的参数说明

    ios开发UI篇—在ImageView中添加按钮以及Tag的参数说明 一.tag参数 一个视图通常都只有一个父视图,多个子视图,在开发中可以通过使用子视图的tag来取出对应的子视图.方法为Viewwi ...

  5. juqery easyui

    私人做程序开发一直有个头疼的问题就是后台管理界面,以前一般都是自己用jquery+ps自己设计的,效果很一般,很不理想. 今天初次使用Jquery EasyUi,简单的做了个布局页面感觉还不错,给大家 ...

  6. Swift学习

    Swift 中文教程(一)基础数据类型 基础类型 虽然Swift是一个为开发iOS和OS X app设计的全新编程语言,但是Swift的很多特性还是跟和Objective-C相似. Swift也提供了 ...

  7. [转]HttpURLConnection的使用

    /* * URL请求的类别分为二类,GET与POST请求.二者的区别在于: * a:) get请求可以获取静态页面,也可以把参数放在URL字串后面,传递给servlet, * b:) post与get ...

  8. Documentum常见问题11-xplore全文检索时找不到相关内容

    最近帮助同事处理了一个关于全文检索的问题,随手记录下来供以后参考. 问题一 某些Cabinet下的文件可以全文检索到,但某些Cabinet下的数据全文检索不成功. 新建了一个Docbase-AADCT ...

  9. uboot 各种烧写命令

    norflash 烧写 (7) Nor Flash指令 Nor Flash 的命令经常用于烧写数据到Nor Flash . flinfo  打印Flash存储器的信息,并列出所有Sector. fli ...

  10. HTML5新增Canvas标签及对应属性、API详解(基础一)

    知识说明: HTML5新增的canvas标签,通过创建画布,在画布上创建任何想要的形状,下面将canvas的API以及属性做一个整理,并且附上时钟的示例,便于后期复习学习!Fighting! 一.标签 ...