Best way to launch storyboard with 3D touch quick action?

141 Views Asked by At

Hi I have two 3D quick action shortcut item in my plist. I put my handler code in App delegate as following:

-(void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler{
    UIStoryboard *storyboard = self.window.rootViewController.storyboard;
    if (storyboard==nil){
        storyboard=[UIStoryboard storyboardWithName:@"Storyboard" bundle:[NSBundle mainBundle]];
    }
    ViewController *vc = [storyboard instantiateInitialViewController];
    self.window.rootViewController = vc;
    if([shortcutItem.type isEqualToString:@"firstItem"]){
        [vc performSegueWithIdentifier:@"firstSegue" sender:self];
    }else{
        [vc handleSecondQuickAction];

    }
}

Basically, there are two scenarios, one is the app first launch, another is the app is already in background and launch from home screen.

I put following code to check if storyboard is alive so that I don't create storyboard again when app is already launched:

UIStoryboard *storyboard = self.window.rootViewController.storyboard;
    if (storyboard==nil){
        storyboard=[UIStoryboard storyboardWithName:@"Storyboard" bundle:[NSBundle mainBundle]];
    }

My problem is here:

if([shortcutItem.type isEqualToString:@"firstItem"]){
        [vc performSegueWithIdentifier:@"firstSegue" sender:self];
    }

If I do quickAction "firstItem" multiple times(by going back to home screen and relaunch with quick action) I get multiply view controllers alive in memory which I consider a memory leak.

I am not sure if I am doing this correctly, I don't launch storyboard from code the project file takes care of that. However quick action handler has to be done programmatically.

What is the best way of launch storyboard with quick action? anyone can provide a good solution? Thanks!

0

There are 0 best solutions below