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. 读《程序员的SQL金典》[2]--函数

    一.数学函数 1.RAND SELECT RAND () ---0.302870228294199 取0-1之间的随机小数. 2.小数取整 CEILINT(data)舍掉小数部分并向上取整. FLOO ...

  2. iptables基本规则

    注意:iptables只能被拥有超级权限的用户设置.   重启 清空 iptables 规则:在终端输入:   iptables -F iptables -X iptables -t nat -F i ...

  3. WP8.1 Study18:动态磁贴

    一.前言 动态磁贴在WindowsPhone8.1和Windows8.1都是其特色,有人喜欢有人讨厌,不过我觉得还是挺好的,可以让使用者很快知道App内的内容和吸引使用者打开App.下面来学习下怎样添 ...

  4. yarn 0.9.0 build spark

    1. 下载scala并安装.版本为2.10.3.设置SCALA_HOME和PATH环境变量 2. 下载SPARK 0.9.0源代码并解压到/root/Downloads/spark-0.9.0-inc ...

  5. enmo_day_07

    数据备份 物理备份 : 底层数据块 逻辑备份 :exp(export), imp(import) 导入导出工具,提取成dump文件,再将dump文件放入数据库 expdp, impdp 数据蹦 uti ...

  6. JS的(function($){})(query)

    function(arg){...} 这就定义了一个匿名函数,参数为arg 而调用函数时,是在函数后面写上括号和实参的,由于操作符的优先级,函数本身也需要用括号,即:(function(arg){.. ...

  7. 在VS下使用 GitFlow管理项目开发

    在VS下使用 GitFlow管理项目开发 1.右键将你的解决方案添加到源代码管理,如果你的VS没有安装git,会提示安装,安装完成之后,在团队资源管理可以看到如下界面 (图一) 2.安装gitflow ...

  8. ffmepg-nginx-nginx-rtmp-module配置脚本

    把上个月写的的配置脚本贴一下: #!/bin/bash #version:-- #create by itn #dis: this is used to auto install ffmpeg+ngi ...

  9. reverse-daily(1)-audio_visual_receiver_code

    本人第一篇随笔,就以一篇CTF逆向分析的文章开始吧! 链接:http://pan.baidu.com/s/1eS6xFIa 密码:u14d 因为re的分析比较琐碎,所以主要就挑一些重点东西来说. 据说 ...

  10. How to browse the entire documentation using XCode 5 Documentation and API Reference ?

    file:///Users/yangiori/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.Ap ...