Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

continueUserActivity not called from search closed app

I am trying to use core spotlight to open a view controller from the spotlight search results.

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void(^)(NSArray *restorableObjects))restorationHandler 
{

if(self.window.rootViewController){
    [self.window.rootViewController restoreUserActivityState:userActivity];
}

return YES;
}

This seems to work when the app is already running in background, however when it is closed and I tap on the spotlight search result it seems that this method gets not called and the behavior I get is that my application simply starts in the main interface.

Do you have any suggestion for making it work also when my app is closed? Is there a way to debug what is happening (since I need to run the app to get the debugger attached I don't know how to simulate the app opening from the search result)?.

like image 312
Niko Zarzani Avatar asked Sep 20 '15 10:09

Niko Zarzani


3 Answers

Niko,

first of all: there's a way to start your app from Xcode and not opening it immediately: open your scheme properties, go to the "run" section, and under "info", there's a switch that will help you to debug what's happening:

"Wait for executable to be launched".

If you activate this switch, you can launch the app from Xcode, Xcode will wait until the app is opened from search and then it will attach the debugger to it.

Hope that helps!

Ivan

like image 104
Ivan Oliver Avatar answered Nov 20 '22 05:11

Ivan Oliver


In the new Swift 5 there is a new new file called SceneDelegate.swift. Use the method scene(_ scene: UIScene, continue userActivity: NSUserActivity)

like image 22
adam eliezerov Avatar answered Nov 20 '22 03:11

adam eliezerov


If you are using the Facebook SDK, and in didfinishlaunching your are returning FBSDK, instead of plain text, and returning true at the end, it can cause problems hitting continueuseractivity.

After searching a lot, and trying different ways, I just had to return true and comment this:

FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)

like image 23
hopye2 Avatar answered Nov 20 '22 05:11

hopye2