user7275929
user7275929

Reputation:

3DTouch Home Screen Quick Actions

I would like to know how I do to create the links of the view's shortcuts ?

How to connect shortcuts 3DTOUCH icons home screen to your correct app view. For example: connect the 3DTouch Home Screen Quick Actions SETTINGS to my settings app view ?

screenshot

Upvotes: 3

Views: 583

Answers (1)

abdul sathar
abdul sathar

Reputation: 2396

Here i post the answer with programmatically add shortcuts with iOS.

include this code in 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;
}

Upvotes: 2

Related Questions