首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >3DTouch主屏幕快速操作

3DTouch主屏幕快速操作
EN

Stack Overflow用户
提问于 2016-12-14 13:22:09
回答 1查看 518关注 0票数 3

我想知道如何创建视图的快捷方式的链接?

如何将快捷方式3DTOUCH图标主屏幕连接到正确的应用程序视图。例如:将3DTouch主屏幕快速操作设置连接到我的设置应用程序视图?

EN

回答 1

Stack Overflow用户

发布于 2016-12-20 14:34:58

在这里,我发布了使用iOS以编程方式添加快捷方式的答案。

将此代码包含在appdelegate.m中

代码语言:javascript
复制
- (void)configDynamicShortcutItems {

    // config image shortcut items
    // if you want to use custom image in app bundles, use iconWithTemplateImageName method
    UIApplicationShortcutIcon *shortcutAddIcon = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeAdd];
//    UIApplicationShortcutIcon *shortcutFavoriteIcon = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeShare];

    UIApplicationShortcutIcon *icon1 = [UIApplicationShortcutIcon iconWithTemplateImageName:@"facebookRXTA.png"];
    UIApplicationShortcutIcon *icon2 = [UIApplicationShortcutIcon iconWithTemplateImageName:@"GoogleRXTA.png"];

    UIApplicationShortcutItem *shortcutSearch = [[UIApplicationShortcutItem alloc]
                                                 initWithType:@"com.youapp.bundleid.Facebook"
                                                 localizedTitle:@"Facebook"
                                                 localizedSubtitle:nil
                                                 icon:icon1
                                                 userInfo:nil];

    UIApplicationShortcutItem *shortcutFavorite = [[UIApplicationShortcutItem alloc]
                                                   initWithType:@"com.youapp.bundleid.Google"
                                                   localizedTitle:@"Google"
                                                   localizedSubtitle:nil
                                                   icon:icon2
                                                   userInfo:nil];

    UIApplicationShortcutItem *shortcutAdd = [[UIApplicationShortcutItem alloc]
                                                   initWithType:@"com.youapp.bundleid.Create new user"
                                                   localizedTitle:@"Create new user"
                                                   localizedSubtitle:nil
                                                   icon:shortcutAddIcon
                                                   userInfo:nil];


    // add all items to an array
    NSArray *items = @[shortcutSearch, shortcutFavorite,shortcutAdd];

    // add the array to our app
    [UIApplication sharedApplication].shortcutItems = items;
}
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler{

    BOOL handledShortCutItem = [self handleShortCutItem:shortcutItem];

    completionHandler(handledShortCutItem);
}
- (BOOL)handleShortCutItem : (UIApplicationShortcutItem *)shortcutItem{

    BOOL handled = NO;

    NSString *bundleId = [NSBundle mainBundle].bundleIdentifier;

    NSString *shortcutSearch = [NSString stringWithFormat:@"%@.Facebook", bundleId];
    NSString *shortcutFavorite = [NSString stringWithFormat:@"%@.Google", bundleId];
     NSString *shortcutAdd = [NSString stringWithFormat:@"%@.Create new user", bundleId];


    if ([shortcutItem.type isEqualToString:shortcutSearch]) {
        handled = YES;

        //Do your navigation or your etc....

    }

    else if ([shortcutItem.type isEqualToString:shortcutFavorite]) {
        handled = YES;

     //Do your navigation or your etc....
    }

   return handled;
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41135390

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档