3D Touch Quick Actions (快捷菜单) 的创建

效果如下:


3D Touch Quick Actions (快捷菜单) 的创建_第1张图片
6E6A80BB2F9387E584F8A93AE97F4FD3.jpg

主要代码如下:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    [self configRootViewController];

    // 动态创建  3D Touch 的 Quick Actions(快捷菜单)
    UIApplicationShortcutItem *item1=[[UIApplicationShortcutItem alloc]initWithType:@"two" localizedTitle:@"购买商城" localizedSubtitle:nil icon:[UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeLove] userInfo:nil];

    UIApplicationShortcutItem *item2=[[UIApplicationShortcutItem alloc]initWithType:@"three" localizedTitle:@"查看信息" localizedSubtitle:nil icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"[email protected]"] userInfo:nil];
    [UIApplication sharedApplication].shortcutItems=@[item1,item2];



    if (launchOptions[@"UIApplicationLaunchOptionsShortcutItemKey"]== nil)
    {
        self.window.rootViewController=[TabBarController new];
        return YES;
    }
    else
    {
        UIApplicationShortcutItem *item=[launchOptions valueForKey:UIApplicationLaunchOptionsShortcutItemKey];

        // 根据我们设置的唯一标识判断
        if([item.type isEqualToString:@"one"])
        {
            TabBarController *tabbar=[TabBarController new];
            tabbar.selectedIndex=0;
            self.window.rootViewController=tabbar;
        }
        return NO;
    }

    return YES;
}

-(void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler
{
    // 根据我们设置的唯一标识判断
    if([shortcutItem.type isEqualToString:@"one"])
    {
        TabBarController *tabbar=[TabBarController new];
        tabbar.selectedIndex=0;
        self.window.rootViewController=tabbar;
    }
    // 根据我们设置的 title 判断
    if ([shortcutItem.localizedTitle isEqual:@"查看信息"])
    {
        TabBarController *tabbar=[TabBarController new];
        tabbar.selectedIndex=1;
        self.window.rootViewController=tabbar;
    }
    else if ([shortcutItem.localizedTitle isEqual:@"购买商城"])
    {
        TabBarController *tabbar=[TabBarController new];
        tabbar.selectedIndex=2;
        self.window.rootViewController=tabbar;
    }
}
@end

你可能感兴趣的:(3D Touch Quick Actions (快捷菜单) 的创建)