Spotlight搜索 - 深层链接集成

时间:2015-08-17 16:21:49

标签: ios objective-c ios9 xcode7 corespotlight

我在聚光灯下收到结果,但是当用户点击它时,它只会启动应用程序,我无法选择该特定产品。

如果有人可以帮助我,那将会非常有用!

谢谢!

到目前为止,这是我的代码:

Comment with Line Comment

2 个答案:

答案 0 :(得分:1)

您正在检查activityType是否存在错误值。

从聚光灯下启动应用时,活动类型为CSSearchableItemActionTypeuserInfo包含一个包含产品标识符的键值对CSSearchableItemActionType

简单的Objective-C示例:

-(BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler
{
    if ([userActivity.activityType isEqualToString:CSSearchableItemActionType])
    {
        NSString *uniqueIdentifier = userActivity.userInfo[CSSearchableItemActivityIdentifier];
        // do stuff to show detail for product with uniqueIdentifier
        return YES; // because you did handle the activity
    }
    return NO; // because you did NOT handle the activity
}

Simple Swift示例:

func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool
{

    if userActivity.activityType == CSSearchableItemActionType {
        let uniqueIdentifier = userActivity.userInfo[CSSearchableItemActivityIdentifier]
        // do stuff to show detail for product with uniqueIdentifier
        return true // because you did handle the activity
    }
    return false // because you did NOT handle the activity
}

答案 1 :(得分:0)

以下检查可以帮助您:

  1. 检查 tabBarController 是否分配正确或是否为零?
  2. 是UITabBarController委托, didSelectViewController 获取 叫?
  3. 稍后,使用断点调试每个导航部分 并尝试找出问题