Contentstack is a headless CMS with an API-first approach. It is a CMS that developers can use to build powerful cross-platform applications in their favorite languages. Build your application frontend, and Contentstack will take care of the rest. Read More.
Contentstack provides iOS SDK to build application on top of iOS. Given below is the detailed guide and helpful resources to get started with our iOS SDK.
Latest Xcode and Mac OS X
To use this SDK on iOS platform, you will have to install the SDK according to the steps given below.
- Download the Latest iOS SDK release and extract the zip file to your local disk.
- Drag and drop Contentstack.framework into your project folder in Xcode. A window will appear, prompting you to choose one of the options for adding files. Click the ‘Destination’ checkbox to copy items into the destination group’s folder. This will add the SDK to your project.
- In the project editor, select your app under TARGETS. Under the General tab, open Linked Frameworks and Libraries and add the following libraries:
- CoreGraphics.framework
- MobileCoreServices.framework
- Security.framework
- SystemConfiguration.framework
- In your target app, click on the Build Settings tab and add the -ObjC flag to Other Linker Flags.
- Add the following line to your Podfile:
- pod 'Contentstack'
- Run pod install, and you should now have the latest Contentstack release.
You can import header file in Objective-C project as:
#import <Contentstack/Contentstack.h>;
You can also import as a Module:
//Objc
@import Contentstack
//Swift
import Contentstack
A stack is like a container that holds the content of your app. Learn more about Stacks.
Content type lets you define the structure or blueprint of a page or a section of your digital property. It is a form-like page that gives Content Managers an interface to input and upload content. Read more.
An entry is the actual piece of content created using one of the defined content types. Learn more about Entries.
Assets refer to all the media files (images, videos, PDFs, audio files, and so on) uploaded to Contentstack. These files can be used in multiple entries. Read more about Assets.
A publishing environment corresponds to one or more deployment servers or a content delivery destination where the entries need to be published. Learn how to work with Environments.
To start using the SDK in your application, you will need to initialize the stack by providing the required keys and values associated with them:
//Objc
Stack *stack = [Contentstack stackWithAPIKey: API_KEY accessToken: ACCESS_TOKEN environmentName: ENVIRONMENT];
//Swift
let stack:Stack = Contentstack.stackWithAPIKey(API_KEY, accessToken: ACCESS_TOKEN, environmentName: ENVIRONMENT)
To get the api credentials mentioned above, you need to log into your Contentstack account and then in your top panel navigation, go to Settings -> Stack to view both your API Key and your Access Token
The stack object that is returned is a Contentstack client object, which can be used to initialize different modules and make queries against our Content Delivery API. The initialization process for each module is explained in the following section.
To fetch all entries of of a content type, use the query given below:
//Obj-C
ContentType *contentTypeObject = [stack contentTypeWithName:@"my_content_type"];
Query *queryObject = [contentTypeObj query];
//Swift
var contentTypeObject:ContentType = stack.contentTypeWithName("my_content_type")
var queryObject:Query = contentTypeObj.query()
To fetch a specific entry from a content type, use the following query:
//Obj-C
ContentType * contentTypeObject = [stack contentTypeWithName:@"my_content_type"];
Entry *entryObject = [contentTypeObject entryWithUID:@"ENTRY_UID"];
//Swift
var contentTypeObject:ContentType = stack.contentTypeWithName("my_content_type")
var entryObject:Entry = contentTypeObject.entryWithUID("ENTRY_UID")
You can query for content types, entries, assets and more using our iOS API Reference.
We have introduced Image Delivery APIs that let you retrieve images and then manipulate and optimize them for your digital properties. It lets you perform a host of other actions such as crop, trim, resize, rotate, overlay, and so on.
For example, if you want to crop an image (with width as 300 and height as 400), you simply need to append query parameters at the end of the image URL, such as, https://images.contentstack.io/v3/assets/blteae40eb499811073/bltc5064f36b5855343/59e0c41ac0eddd140d5a8e3e/download?crop=300,400. There are several more parameters that you can use for your images.
Read Image Delivery API documentation.
You can use the Image Delivery API functions in this SDK as well. Here are a few examples of its usage in the SDK.
//Obj-C
/* set the image quality to 100 */
NSDictionary *params = [[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithInt:100], @"quality", nil];
NSString *transformedUrl = [stack imageTransformWithUrl:imageURL andParams:params];
/* resize the image by specifying width and height */
NSDictionary *params = [[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithInt:100], @"width", [NSNumber numberWithInt:100], @"height", nil];
NSString *transformedUrl = [stack imageTransformWithUrl:imageURL andParams:params];
/* enable auto optimization for the image */
NSDictionary *params = [[NSDictionary alloc] initWithObjectsAndKeys:@"webp", @"auto", nil];
NSString *transformedUrl = [stack imageTransformWithUrl:imageURL andParams:params];
//Swift
/* set the image quality to 100 */
let params:[String : AnyObject?] = [
"quality":100 as AnyObject
];
let transformedUrl:String = stack.imageTransformation(withUrl: imageURL, andParams: params);
/* resize the image by specifying width and height */
let params:[String : AnyObject?] = [
"width":100 as AnyObject,
"height":100 as AnyObject,
];
let transformedUrl:String = stack.imageTransformation(withUrl: imageURL, andParams: params);
let params:[String : AnyObject?] = [
"auto":"webp" as AnyObject
];
let transformedUrl:String = stack.imageTransformation(withUrl: imageURL, andParams: params);
Copyright (c) 2017, Contentstack.io.
All rights reserved.