0

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.

rocky
  • 7,506
  • 3
  • 33
  • 48
Lee Probert
  • 10,308
  • 8
  • 43
  • 70

2 Answers2

1

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.

Codename of Content Type

Martin Makarsky
  • 2,580
  • 1
  • 17
  • 28
  • Thanks for this response. I did wonder if it was the codename for the Content Type and NOT a piece of content. I am trying to get the content types for the values of a LinkedElementType. There doesn't seem to be a way to access the types. The value property is an array of strings representing their codenames. – Lee Probert Jul 03 '19 at 21:24
  • Looking deeper into this, and I can't see any way to get the content type for a piece of content from its codename so that I can then use getItem and dynamically map it to my class. – Lee Probert Jul 03 '19 at 21:34
  • You can access the type for each linked element from the ItemsResponse JSON. It would be [modular_content][][system][type] – Lee Probert Jul 03 '19 at 22:07
0

I also had the same thought usps tracking but thanks that you have provided a question.

Thanks and Regards, Shane.