This demo iOS news app is built using Contentstack’s iOS SDK. It uses Contentstack to store and deliver the content of the news app.View Code
Here’s a quick guide on how to create a news app for iOS using iOS SDK and Contentstack.
Note: For this tutorial, we have assumed that you are familiar with Contentstack and iOS. If not, then please refer to the docs (Contentstack docs) for more details.
In this tutorial, we will first go through the steps involved in configuring Contentstack, and then look at the steps required to customize and use the presentation layer.
Log in to your Contentstack account, and create a new stack. This stack will hold all the data, specific to your website. Learn more on how to create a stack.
To add an environment in Contentstack, navigate to ‘Settings' -> 'Environment', and click on the '+ New Environment’ tab. Provide a suitable name for your environment, say ‘staging’. Specify the base URL (e.g., ‘http://YourDomainName.com’), and select the language (e.g., English - United States). Then, click on 'Save'. Read more about environments.
A content type is like the structure or blueprint of a page or a section of your web or mobile property. Read more about Content Types.
For this website, two basic content types are required: Category and News. For quick integration, we have already created these content types. You simply need to import them to your stack. (You can also create your own content types. Learn how to do this).
To import the content types, first save the zipped folder of the JSON files given below on your local machine. Extract the files from the folder. Then, go to your stack in Contentstack. The next screen prompts you to either create a new content type or import one into your stack. Click the ‘Import’ link, and select the JSON file saved on your machine.
Here’s a brief overview of the content types required for this project.
Now that all the content types are ready, let’s add some content for your news app.
Create and publish entries for the ‘News’ and ‘Category’ content types
With this step, you have created sample data for your website. Now, it’s time to use and configure the presentation layer.
To set up Xcode and initialize iOS SDK, refer to our documentations, here.
To get your app up and running quickly, we have created a sample iOS app for this project. You need to download it and change the configuration. Download the app using the command given below:
$ git clone https://github.com/raweng/NewsApp-iOS.git
Once you have downloaded the project, add your Contentstack API Key, Access Token, and Environment to the project during the SDK initialization step:
Stack stack = Contentstack.stack(context, "API_KEY","ACCESS_TOKEN","ENVIRONMENT_NAME");
This will initiate your project.
Now that we have a working project, you can build and run it.