3DTouch主屏幕快速操作

时间:2016-12-14 05:22:09

标签: objective-c xcode 3dtouch

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

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

screenshot

1 个答案:

答案 0 :(得分:1)

在这里,我以编程方式添加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;
}