2

iOS 9.2, xCode 7.2, Objective-C

I used this tutorial (Core Spotlight version) but translated it into Objective-C: http://code.tutsplus.com/tutorials/ios-9-introducing-search-apis--cms-24375

Everything works except one thing - I can't get callback when user taps the search result. It seems I need to write the following method in my app delegate:

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

But it is not called at all. How to solve this issue?

Vyachaslav Gerchicov
  • 2,317
  • 3
  • 23
  • 49

1 Answers1

6

You have to first check your activity has type search action :

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void(^)(NSArray * __nullable restorableObjects))restorationHandler 
{
    if ([[userActivity activityType] isEqualToString:CSSearchableItemActionType]) 
    {
        NSString *uniqueIdentifier = [userActivity.userInfo objectForKey:CSSearchableItemActivityIdentifier];
        NSLog(@"%@",uniqueIdentifier);
        // Launch Detail controller
    }
return YES;
}

Hope it helps you!!

Pushpa Y
  • 1,010
  • 1
  • 12
  • 20
  • 1
    look at the question more attentively - I've already answered that it is not called. The only idea I have is this tutorial is partially incorrect and this method is called for `NSUserActivity`, not `Core Spotlight` which means at least I can't define multiple objects to handle (for example if I wrote browser then I can run this browser but can't view in spotlight multiple pages from history and can't allow user to go to any of them – Vyachaslav Gerchicov Jan 05 '16 at 07:45
  • @VyachaslavGerchicov Sorry!! Now i edited the answer. You have to implement different method in objective c. – Pushpa Y Jan 05 '16 at 08:54
  • Thanks, I'll try it later. But the only thing I still can't understand is you call `[userActivity becomeCurrent]` so you have only one "activity" at the same time. But what if I need for example a queue of 3 last activities? Or should `Core Spotlight` call this method even without explicit `NSUserActivity` declaration. – Vyachaslav Gerchicov Jan 05 '16 at 09:31
  • 1
    finally solved it. The app I edit is not my own and there are several app delegates and only one inherits `UIApplicationDelegate` I need. – Vyachaslav Gerchicov Jan 12 '16 at 12:23