Apple’s iOS is the world’s second most popular mobile operating system and it’s not a secret that iOS users spend much more on their devices compared to Android users. To ease the difficult process of implementing native apps for Apple’s ecosystem devices, we’ve created the Kentico Cloud SDK written in Swift.
Development for Apple’s Devices
For those not familiar with Apple’s development stack, there is a relatively new programming language called Swift. Swift was introduced in 2014, became open source a year later, and is now one of the fastest-growing programming languages out there.
It has always been possible to create iOS apps with content from Kentico Cloud, but you had to deal with all the network communication, crafting queries, parsing JSON responses, mapping models, and much more on your own.
But now we introduce Kentico Cloud Swift SDK, and in this blog post I’d like to show you how you can utilize it to deliver content for your iOS apps (as well as watchOS, OS X, and tvOS).
Features of the Kentico Cloud Swift SDK
The Kentico Cloud Swift SDK helps you with retrieving content, adding contacts, and tracking activities. There are several features you can use in your next project:
- getting content items
- getting content types
- getting taxonomies
- tracking activities
- adding contacts
And the best thing? You don’t have to do all the difficult stuff like networking and object mapping—all this is done by the SDK itself. Let’s show you how to integrate SDK into a project and look at some basic usage.
Adding SDK into Your Project
And run pod install. This command will add KenticoCloud SDK with all the necessary dependencies to your project.
Creating a Type Object
Mapping proprietary responses to strongly typed objects is one of the biggest and most boring parts of integrating with any third-party service. But most of the work is done by the SDK itself, so you just need to define what you want to store in your strongly typed object.
For example, let’s say we want to get articles from Kentico Cloud—an article has a title (the Text element), an asset (the Asset element), and a postDate (the Date & Time element). We have two options here:
- Using strongly typed mapping provided by built-in element types
- Using custom mapping
Getting and Using Items
In order to get items, you just need to create an instance of the DeliveryClient with your project Id and pass a query to the getItem/getItems methods. You have two options for creating a query:
- You can use a strongly typed object query.
- For more advanced queries, you can craft a query on your own—the process for crafting queries is the same as in the Kentico Cloud Delivery documentation.
The last step is getting items from the Cloud and using them in your app. Requested items are returned to the completion handler. The Completion handler is just a simple callback which contains received items.
Single Items, Taxonomies, and Content Types
Getting Modular Content
If your items contain some linked modular content, you can get this content directly from the deliveryResponse object—there is no need to make further server requests. You can get modular content with a codename of a certain type:
While developing your apps, you may encounter strange behavior. To reduce this, you can pass a debug flag to the DeliveryClient object and you will be provided with additional messages in the output about your requests. You can add the optional enableDebugLogging flag:
Adding Contacts and Tracking Activities
Unlike traditional web analytics tools, Kentico Cloud tracks individual visitors and builds a complete picture of their activities. With this SDK, you can track your users even on iOS devices. You just need to start a session and track custom activity or add contacts:
Where to Go from Here
You can find more information about features and usage of the SDK in our public GitHub repository. If you’re lacking any feature, do not hesitate to let us know in the discussion forums or create a new GitHub issue! We also have API reference documentation where you can find all our features.
Do you have any lingering questions? Get them answered in the forum below!