Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to get Static 3D touch Quick Actions to work in Obj-C

So I want a pretty basic 3D touch setup. On my main UI, I have a 2 option segmented control and I basically want to have one option of it selected upon open when 3DQuickActionA is used, and the other option when 3DTouchQuickActionB is used.

I've looked at other questions on this site, and one suggested I use:

- (void)handleShortCutItem:(UIApplicationShortcutItem *)shortcutItem  {
if([shortcutItem.type isEqualToString:@"3DQuickActionA"]){
    self.quote_opt.selectedSegmentIndex = 0;    }
if([shortcutItem.type isEqualToString:@"3DQuickActionB"]){
    self.quote_opt.selectedSegmentIndex = 1;    }
}

where quote_opt is the name of my segmented control.

However, this doesn't work. My app launches ok, but just has whatever the last value of quote_opt was as the current option-- the 3D touch actions do nothing. I'm sure I'm missing something, but I don't know what. Does something need to go in viewdidload?

Any advice would be appreciated, and I'm happy to post whatever other portions of code/answer any other questions needed to solve the problem.

Thank you!

like image 805
Branch Avatar asked Aug 21 '17 13:08

Branch


1 Answers

You also need to check the launchOptions in didFinishLaunchingWithOptions.

So, as the result of the ongoing chat, here's the latest code:

AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [FIRApp configure];

    if(launchOptions)
    {
        UIApplicationShortcutItem *selectedItem = [launchOptions objectForKey:UIApplicationLaunchOptionsShortcutItemKey];

        if(selectedItem)
        {
            [self applyShortcutItem:selectedItem];
        }
    }
    return YES;
}

- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler
{
    [self applyShortcutItem:shortcutItem];
}

- (void)applyShortcutItem:(UIApplicationShortcutItem *)shortcutItem
{
    ViewController *rootViewController = (ViewController *)[self.window rootViewController];

    if([shortcutItem.type isEqualToString:@"DogModeShortcut"])
    {
        [rootViewController setShortcutAction:LaunchDogMode];
    }
    else if([shortcutItem.type isEqualToString:@"CatModeShortcut"])
    {
        [rootViewController setShortcutAction:LaunchCatMode];
    }
}
like image 135
EDUsta Avatar answered Sep 26 '22 00:09

EDUsta