Today we announce the availability of the iOS SDK which enables iOS apps to access your iKnode API. You can download the code @ SDK’s github repository.
The SDKs are built with the purpose of making it easier to access your API through the REST interface. It is not required for you to learn how to use the SDKs at all. Our REST API is very friendly as well, but we do recommend using it; it makes it so much easier.
The SDK follows exactly the same philosophy for all platforms. This means that if you know how to use the Javascript SDK or the C# SDK, the iOS SDK will be a piece of cake.
For this example we are going to use the following API:
usingSystem;usingiKnode.Applications;usingiKnodeSdk.UnitTest.Domain;namespaceiKnodeSdkTest{/// <summary>/// Defines the User Service./// </summary> [Application]publicclassUserService{/// <summary>/// Gets the User First Name by its identifier./// </summary>/// <param name="id">User Identifier.</param>/// <returns>User First Name/.</returns>publicstringGetFirstNameById(intid){return"Robert";}/// <summary>/// Gets the Most Common User First Name./// </summary>/// <returns>Most Common User First Name/.</returns>publicstringGetMostCommonFirstName(){return"John";}/// <summary>/// Gets the User by its identifier./// </summary>/// <param name="id">User Identifier.</param>/// <returns>User Information.</returns>publicUserGetById(intid){if(id!=1){returnnull;}returnnewUser(1,newFullName("John","Doe"));}/// <summary>/// Saves the User Information./// </summary>/// <param name="user">User Information.</param>/// <returns>User Identifier.</returns>publicintSave(Useruser){if(user==null){return-1;}//TODO: Here your store the User Information.returnuser.Id;}/// <summary>/// Creates a new User with the Default Information./// </summary>/// <returns>User Information.</returns> publicUserCreateDefault(){returnnewUser(2,newFullName("Jane","Doe"));}/// <summary>/// Creates a new User./// </summary>/// <param name="id">Identifier.</param>/// <param name="name">Name.</param>/// <returns>User Information.</returns> publicUserCreate(intid,FullNamename){returnnewUser(id,name);}}}
The model used by the iKnode Application is the following:
namespaceiKnodeSdkTest{/// <summary>/// Defines the Full Name class./// </summary> [Serializable]publicclassFullName{/// <summary>/// First Name./// </summary>publicstringFirstName;/// <summary>/// Last Name./// </summary>publicstringLastName;/// <summary>/// Initializes a new instance of the <see cref="FullName"/> class./// </summary>/// <param name="firstName">First Name/</param>/// <param name="lastName">Last Name.</param>publicFullName(stringfirstName,stringlastName){this.FirstName=firstName;this.LastName=lastName;}}/// <summary>/// Defines the User class./// </summary> [Serializable]publicclassUser{/// <summary>/// Identifier./// </summary>publicintId;/// <summary>/// Full Name./// </summary>publicFullNameName;/// <summary>/// Initializes a new instance of the <see cref="User"/> class./// </summary>/// <param name="id">Identifier.</param>/// <param name="name">Name.</param>publicUser(intid,FullNamename){this.Id=id;this.Name=name;}}}
This API is the same used to demostrate the usage with the Javascript and C# SDKs.
Using just the REST endpoint we would call this API in the following way:
In the iOS SDK the return type is usually NSDictionary for complex objects as seen in the following example:
Using Objective-C
123456789101112131415
ApplicationClient*client=[[ApplicationClientalloc]initWithServiceUrl:BaseUrlAndUserId:UserIdAndApiKey:ApiKeyAndAppName:@"UserService"];NSDictionary*params=[NSDictionarydictionaryWithObject:@"1"forKey:@"id"];NSData*data=[clientExecuteWithMethodName:@"GetById"AndParameters:params];NSDictionary*user=(NSDictionary*)data;// User Iduser["Id"];// User Full Nameuser["FullName"];
Hope you find it useful. This SDK, as well as all the others are open source and can be found in here. You can use them as you wish.