Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios CSSearchableIndex和NSUserActivity在搜索API中的区别是什么?多久打一次电话?_Ios_Ios Searchapi - Fatal编程技术网

Ios CSSearchableIndex和NSUserActivity在搜索API中的区别是什么?多久打一次电话?

Ios CSSearchableIndex和NSUserActivity在搜索API中的区别是什么?多久打一次电话?,ios,ios-searchapi,Ios,Ios Searchapi,我在iOS9Sampler中看到了下面的代码,以便在ios9中使用搜索API。它同时使用NSUserActivity和CSSearchableIndex。所以我想问一个问题: 什么时候应该使用nsserActivity,什么时候应该使用CSSearchableIndex?我看到在聚光灯下搜索时也会得到同样的结果 下面的代码调用视图控制器的每个viewDidLoad。对吗?还是应该只打一次电话?我怎样才能确认打过一次电话 免疫活性 您正在索引的内容类型以及用户与之交互的方式将决定是否适合使用NSU

我在iOS9Sampler中看到了下面的代码,以便在ios9中使用
搜索API
。它同时使用
NSUserActivity
CSSearchableIndex
。所以我想问一个问题:

  • 什么时候应该使用
    nsserActivity
    ,什么时候应该使用
    CSSearchableIndex
    ?我看到在聚光灯下搜索时也会得到同样的结果
  • 下面的代码调用视图控制器的每个
    viewDidLoad
    。对吗?还是应该只打一次电话?我怎样才能确认打过一次电话
  • 免疫活性


    您正在索引的内容类型以及用户与之交互的方式将决定是否适合使用
    NSUserActivity
    CSSearchableItem

    这在中进行了解释,并针对两种不同的场景提供了示例,因此请务必彻底检查这一点。一些注意事项:

    • 当用户在中执行活动时,使用
      NSUserActivity
      为项目编制索引 您的应用程序,例如访问导航点或创建和查看 内容
    • 使用Core Spotlight将特定于应用程序的内容添加到设备上 索引,例如持久用户数据-文档、照片和其他 内容类型
    • CSSearchableItem
      不要求用户访问内容, 不同于
      nsserActivity
    • CSSearchableItem
      不可公开索引,而
      NSUserActivity
        let activityType = String(format: "%@.%@", uniqueIdentifier, domainIdentifier)
        activity = NSUserActivity(activityType: activityType)
        activity.title = "iOS-9-Sampler_NSUserActivity"
        activity.keywords = Set<String>(arrayLiteral: "dog", "cat", "pig", "sheep")
        activity.eligibleForSearch = true
        activity.becomeCurrent()
    
        let attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeImage as String)
        attributeSet.title = "iOS-9-Sampler_CoreSpotlight"
        attributeSet.contentDescription = "iOS-9-Sampler is a code example collection for new features of iOS 9."
        attributeSet.keywords = ["dog", "cat", "bird", "fish"]
        let image = UIImage(named: "m7")!
        let data = UIImagePNGRepresentation(image)
        attributeSet.thumbnailData = data
    
        let searchableItem = CSSearchableItem(
            uniqueIdentifier: uniqueIdentifier,
            domainIdentifier: domainIdentifier,
            attributeSet: attributeSet)
    
        CSSearchableIndex.defaultSearchableIndex().indexSearchableItems([searchableItem]) { (error) -> Void in
            if error != nil {
                print("failed with error:\(error)\n")
            }
            else {
                print("Indexed!\n")
            }
        }