Developing native Appcelerator modules – Part II – iOS module
Part II – building a native Appcelerator module for iOS
Start by creating a new “Mobile Module Project.” To do this, right-click your Titanium App project in Appcelerator Studio, then select “New” and “Mobile Module Project.” Appcelerator will create an Xcode project for us.
Open the module project in Xcode and take a note that AppceleratorStudio created four Objective-C files: TiVkModuleAssets.h, TiVkModuleAssets.m and TiVkModule.h, TiVkModule.m. We won’t alter the automatically generated assets files. Some developers starting with Appcelerator modules development might get confused by Titanium documentation mentioning views and proxies necessary to implement visual elements. To make it clear, in our case, the module is only invoked through API methods. There are no buttons and/or similar. Hence, we won’t, at this time, make a use of these proxies/views.
In TiVkModule.h, we add the public properties and methods to the interface.
* Appcelerator module for social network VK
* Created by Diophant Technologies, OU
* Copyright (c) 2015 Diophant Technologies. All rights reserved.
// VK permissions for public API
enum : NSUInteger
The most important method is authorize. Let’s quickly code the initial implementation.
* JS example:
* var vk = require('ti.vk');
* vk.appid = '1234567';
* vk.permissions = [
// we can only authorize for a specific app
if (nil == appid)
[self throwException:@"missing appid" subreason:nil location:CODELOCATION];
Let’s also implement more authorize methods with appropriate signatures as below.
- (void) authorizeForceOAuth:(id)sender
[VKSdk authorize:SCOPE revokeAccess:YES forceOAuth:YES];
Now, we can finish implementing methods, like the below.
// called when authorization succeeded
- (void) vkSdkReceivedNewToken:(VKAccessToken*) newToken
NSMutableDictionary *event = [NSMutableDictionary dictionaryWithObjectsAndKeys:
token = [newToken accessToken];
[self fireEvent:@"login" withObject:event];
Once we implemented all methods, let’s ensure that module.xcconfig includes a reference to the utilized VKSdk.framework framework so we could build our module with the Appcelerator Studio generated build.py script.
Add the newly created module to your Appcelerator project from Help->Install Mobile Module… and adjust tiapp.xml.
The last step is to replace the require statement and we can use the brand new ti.vk native iOS module in our app.
We can now utilize the native iOS VK module to build Appcelerator apps. In the next installment, we will learn how to make our module work on Android.