关于3D Touch从app图标快速入口篇.

来源:互联网 发布:java log4j slf4j 编辑:程序博客网 时间:2024/05/04 17:42


经过最近几天的研究,本人已经做出了一套快速入口的小demo,并且可以让模拟器进行3D Touch的快速入口效果.


一: 让模拟器可以测试3D Touch的快速入口效果步骤(本人也是在github上发现的方法,再次总结一下):

 模拟器测试3D Touch的方法
 1. 打开终端
 2. git clone https://github.com/DeskConnect/SBShortcutMenuSimulator.git
 3. cd SBShortcutMenuSimulator
 4. make
 5. 打开写好的程序 运行打开模拟器
 6. xcrun simctl spawn booted launchctl debug system/com.apple.SpringBoard --environment DYLD_INSERT_LIBRARIES=$PWD/SBShortcutMenuSimulator.dylib
 7. xcrun simctl spawn booted launchctl stop com.apple.SpringBoard   终端运行完这句话模拟器会黑一下 几秒就好了
 
 8. echo 'cn.bobo.shortcut' | nc 127.0.0.1 8000    注意: 'cn.bobo.shortcut'  ''里边写的是自己项目的Bundle identifier.  

 注意:  每次想要启动快速入口都要重复操作第8步.
 
 快速入口两种配置方法: 静态配置和动态配置  静态配置直接在info.plist里边配置就好了  这个示例是动态配置的.


二: 快速入口代码实现如下:

           didFinishLaunchingWithOptions... 方法中实现以下代码:

           点击app图标会弹出一个类似于tableview的一个弹框,这个弹框是系统已经设置好的,我们只需要给上边添加东西即可. item理解为就是每个tableview的cell.

    UIApplicationShortcutIcon *firstItemIcon = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeAdd];

    UIMutableApplicationShortcutItem *firstItem = [[UIMutableApplicationShortcutItem alloc]initWithType:@"first" localizedTitle:@"第一个item" localizedSubtitle:nil icon:firstItemIcon userInfo:nil];
    
    UIApplicationShortcutIcon *secondItemIcon = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeAdd];
    UIMutableApplicationShortcutItem *secondItem = [[UIMutableApplicationShortcutItem alloc]initWithType:@"second" localizedTitle:@"第二个item" localizedSubtitle:nil icon:secondItemIcon userInfo:nil];
    
    application.shortcutItems = @[firstItem,secondItem];


   以下这个方法就是用来判断用户点的是哪一个item,想必很好理解

-(void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler{

    UINavigationController *nav =(UINavigationController *) [UIApplication sharedApplication].keyWindow.rootViewController;

    if ([shortcutItem.type isEqual:@"first"]) {
        
        NSLog(@"跳转到firstItem界面");

        firstItemView *first = [[firstItemView alloc]init];
        
        [nav pushViewController:first animated:YES];
        
    }else if([shortcutItem.type isEqual:@"second"]){
    
        NSLog(@"跳转到secondItem界面");
        
        secondItemView *second = [[secondItemView alloc]init];
        
        [nav pushViewController:second animated:YES];
    }
}



就这样 3D Touch中快速入口就完了......  是不是很快....................


0 0
原创粉丝点击