I am using the Kentico-cloud Swift SDK to grab a bunch of elements from the CMS using the Delivery API in the background.
One of the Swift SDK methods allows me to get a ContentType for a certain element on the CMS so I can then map it to an object in my code. Here's the code:
self.client.getContentType(name: codename, completionHandler: { (isSuccess, contentType, error) in
guard error == nil else {
print(error!)
return
}
if isSuccess {
if let type = contentType {
print(type)
self.client.getItem(modelType: type, itemName: codename, completionHandler: { (isSuccess, deliveryItem, error) in
if isSuccess {
// save this Element
print(deliveryItem)
} else {
if let error = error {
print(error)
}
}
})
}
}
})
the attribute codename
is the name of the object I am trying to find the ContentType
for. The call succeeds and I get my ContentType
object, unfortunately, it does not have any properties in it that aren't nil
.
I assume it should give me the name of the type as a String so I can then map it to my class.
Could you verify you have valid content type codename in the name parameter? I've tried to reproduce it (see attached screenshot) and everything works on my side (there is also test for this feature which passes as well in GetContentType.swift
).
Could you post the value of a requestUrl
property from DeliveryClient.swift
getContentType()
method line 176?
Edit: Oh, from your screen on the GitHub issue I can see you are trying to get the content type with the codename of the item which in wrong. You should use the codename of the content type.
From the docs for getContentType()
method:
/** Gets single content type from Delivery service. - Parameter name: The codename of a specific content type. - Parameter completionHandler: A handler which is called after completetion. - Parameter isSuccess: Result of the action. - Parameter contentTypes: Received content type response. - Parameter error: Potential error. */
You can learn more about content types here.