3DTouch主屏幕快捷操作

3
我想知道如何创建视图快捷方式的链接?
如何将3D Touch图标主屏幕的快捷操作连接到正确的应用视图。 例如:将3D Touch主屏幕快速操作设置与我的设置应用程序视图连接?
请参考以下截图:https://istack.dev59.com/CC0VL.webp

请阅读 如何提出好问题 并相应地编辑您的问题,这将极大地提高您获得好回答的机会,避免您的问题被贴下或关闭。 - Wim Ombelets
你在处理主屏幕快速操作方面遇到了困难吗?或者你有兴趣创建一个设置页面来配置快速操作吗? - grane2212
1个回答

2

在这里我将介绍如何通过编程方式添加iOS快捷方式。

请将以下代码添加到appdelegate.m文件中。

- (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;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接