OGeek|极客世界-中国程序员成长平台

标题: ios - 无法在缓存中找到具有标识符 - id - 的可缓存对象 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 14:38
标题: ios - 无法在缓存中找到具有标识符 - id - 的可缓存对象

我正在尝试在我的应用中为 Siri 实现 INCreateNoteIntent。 Siri解析了所有需要的内容,她通过confirm和handle intent方法,一切正常,但Siri的最终响应是:

抱歉,应用出现问题

控制台日志中打印的是这样的:

[意图] -[INCache cacheableObjectForIdentifier:] 无法在缓存中找到标识符为 5BCBE5F9-5DD6-4E63-AF5C-F3863BF56ECD 的可缓存对象。

有什么想法吗?



Best Answer-推荐答案


我在使用 INCreateTaskListIntent 时遇到了同样的问题。也许您对 INCreateNoteIntent 也有类似的问题?

事实证明,在您在 handle 方法中创建的最终响应中,您必须为响应分配一个新的 INTaskList 对象,否则它不是有效的成功响应(即,成功的响应必须设置 createdTaskList 字段)。也许你的笔记问题是类似的?

这是修复前后的代码示例:

之前(我不是创建和设置任务列表):

func handle(intent: INCreateTaskListIntent, completion: @escaping (INCreateTaskListIntentResponse) -> Void) {
    guard let title = intent.title else {
        completion(INCreateTaskListIntentResponse(code: .failure, userActivity: nil))
        return
    }

    print("Creating task list called \(title)")
    let response = INCreateTaskListIntentResponse(code: .success, userActivity: nil)
    completion(response)
}

之后(我设置了任务列表):

func handle(intent: INCreateTaskListIntent, completion: @escaping (INCreateTaskListIntentResponse) -> Void) {
    guard let title = intent.title else {
        completion(INCreateTaskListIntentResponse(code: .failure, userActivity: nil))
        return
    }

    print("Creating task list called \(title)")
    let taskList = INTaskList(
        title: title,
        tasks: [],
        groupName: nil,
        createdDateComponents: nil,
        modifiedDateComponents: nil,
        identifier: "superduperlist"
    )
    let response = INCreateTaskListIntentResponse(code: .success, userActivity: nil)
    response.createdTaskList = taskList
    completion(response)
}

关于ios - 无法在缓存中找到具有标识符 - id - 的可缓存对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49152758/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4