我正在测试 Kentico Cloud Swift SDK 以返回一些“文章”内容类型(我创建了其中两个并已发布)。
我正在使用此处描述的样板代码:
我得到的结果是:[Kentico Cloud] Getting items action has succeeded. Received nil items.
我的代码:
let client = DeliveryClient.init(projectId: <project id>, previewApiKey: <preview key>, secureApiKey: <secure key>, enableDebugLogging: true)
func getArticles(){
// Note: Using "items" as custom query returns all content items,
// but to map them to a single model, a filter is needed.
let customQuery = "items?system.type=article"
// More about strongly-typed models https://github.com/Kentico/cloud-sdk-swift#using-strongly-typed-models
client.getItems(modelType: Article.self, customQuery: customQuery) { (isSuccess, itemsResponse, error) in
if isSuccess {
// We get here and itemsResponse != nil but items == nil
if let articles = itemsResponse?.items {
for article in articles {
}
}
} else {
if let error = error {
print(error)
}
}
}
}
ObjectMapper
我相信在触发将 JSON 转换为 Article 对象之前会出现此错误消息。不过我可能是错的。
有人有想法么?
更新有趣的是,如果我请求这样的单个文章对象......
client.getItem(modelType: Article.self, itemName: <codename>) { (isSuccess, itemResponse, error) in
if isSuccess {
if let article = itemResponse?.item {
// Use your item here
}
} else {
if let error = error {
print(error)
}
}
}
...然后它的工作原理。我得到了文章对象。它只是要求所有失败的文章。