Next Blog Link: Extending Titanium Mobile App
http://ashishnigamblog.blogspot.in/2013/01/extending-titanium-mobile-application.html
http://ashishnigamblog.blogspot.in/2013/01/extending-titanium-mobile-application.html
Module template Link:: https://docs.google.com/open?id=0B0PuCdyscdjPaTctT0V4LUtCSlE
How to use Module template for Titanium iOS Module Development.
Steps to use:
1: Download zip file from the above link, and unzip it.
2: It will generate a folder named template, and inside that folder there is a file "template.xcodeproj".
3: double click this file to open the project in Xcode.
4: Project contains various file, uses of these are mentioned with file names below.
File Names:
1:ComGlTemplateModuleAssets.h
2:ComGlTemplateModuleAssets.m
These files are generated files and not meant to be edited.
1:ComGlTemplateModule.h
2:ComGlTemplateModule.m
This is the module file which is always required for module development and can be single file only.
1:ComGlTemplateSampleProxy.h
2:ComGlTemplateSampleProxy.m
Its Proxy class, Object of this class can be created in JS files of titanium app and Methods declared in this class can be called using dot notation, if the method signature is according to the Titanium standards. This class is basically created to show case all the LIFE CYCLE Methods of a Proxy Class Object Creation Process, which will be called one by one in a sequence.
1:ComGlTemplateSampleView.h
2:ComGlTemplateSampleView.m
Its a View class, and It require a view proxy to be associated with it. view proxy can be made available using the naming convention.
So according to the naming convention its view proxy will be ComGlTemplateSampleViewProxy.h and ComGlTemplateSampleViewProxy.m class files.
1:ComGlTemplateSampleViewProxy.h
2:ComGlTemplateSampleViewProxy.m
Its view proxy for Sample View class and When ever Titanium developer create the instance of the view the This proxy class instance will be created and methods exposed in the proxy will be available to the JS developer.
1: Download zip file from the above link, and unzip it.
2: It will generate a folder named template, and inside that folder there is a file "template.xcodeproj".
3: double click this file to open the project in Xcode.
4: Project contains various file, uses of these are mentioned with file names below.
File Names:
1:ComGlTemplateModuleAssets.h
2:ComGlTemplateModuleAssets.m
These files are generated files and not meant to be edited.
1:ComGlTemplateModule.h
2:ComGlTemplateModule.m
This is the module file which is always required for module development and can be single file only.
1:ComGlTemplateSampleProxy.h
2:ComGlTemplateSampleProxy.m
Its Proxy class, Object of this class can be created in JS files of titanium app and Methods declared in this class can be called using dot notation, if the method signature is according to the Titanium standards. This class is basically created to show case all the LIFE CYCLE Methods of a Proxy Class Object Creation Process, which will be called one by one in a sequence.
1:ComGlTemplateSampleView.h
2:ComGlTemplateSampleView.m
Its a View class, and It require a view proxy to be associated with it. view proxy can be made available using the naming convention.
So according to the naming convention its view proxy will be ComGlTemplateSampleViewProxy.h and ComGlTemplateSampleViewProxy.m class files.
1:ComGlTemplateSampleViewProxy.h
2:ComGlTemplateSampleViewProxy.m
Its view proxy for Sample View class and When ever Titanium developer create the instance of the view the This proxy class instance will be created and methods exposed in the proxy will be available to the JS developer.
1:ComGlTemplateSampleDemoProxy.h
2:ComGlTemplateSampleDemoProxy.m
This DemoProxy class methods are provided to explain certain features like how to fire event and callback methods. This class also explains some of the property change notification methods.
1:ComGlTemplateMethodsandParameterProxy.h 2:ComGlTemplateMethodsandParameterProxy.m
This class explains all the possible values of return type, which can be returned to the JS developer.
It also uses the standards for the methods used by titanium, and it must be followed.
Note: module.xcconfig file is written with some commented code to explain some of the findings and logical relationship between titanium and native platform.
In actual module development these commented things are to be used as required.
How to Build and Package the Module.
Refer the following link for this. https://wiki.appcelerator.org/display/guides/iOS+Module+Development+Guide
How to create the objects of deferent classes: Steps:
1: require the Module
example:
var template = require('com.gl.template'); Note: "com.gl.template" will be your module id.
Method Calling Example:
template.METHODofModuleClass();
2:create the object of proxy class before calling there methods.
example:
var sampleProxyObject = template.createSample(); or
var sampleProxyObject = template.createSample({});
Note: "createSample()" here "Sample" is the name used while creating proxy class, i.e. ComGlTemplateSampleProxy.
2:ComGlTemplateSampleDemoProxy.m
This DemoProxy class methods are provided to explain certain features like how to fire event and callback methods. This class also explains some of the property change notification methods.
1:ComGlTemplateMethodsandParameterProxy.h 2:ComGlTemplateMethodsandParameterProxy.m
This class explains all the possible values of return type, which can be returned to the JS developer.
It also uses the standards for the methods used by titanium, and it must be followed.
Note: module.xcconfig file is written with some commented code to explain some of the findings and logical relationship between titanium and native platform.
In actual module development these commented things are to be used as required.
How to Build and Package the Module.
Refer the following link for this. https://wiki.appcelerator.org/display/guides/iOS+Module+Development+Guide
How to create the objects of deferent classes: Steps:
1: require the Module
example:
var template = require('com.gl.template'); Note: "com.gl.template" will be your module id.
Method Calling Example:
template.METHODofModuleClass();
2:create the object of proxy class before calling there methods.
example:
var sampleProxyObject = template.createSample(); or
var sampleProxyObject = template.createSample({});
Note: "createSample()" here "Sample" is the name used while creating proxy class, i.e. ComGlTemplateSampleProxy.
Method Calling Example:
sampleProxyObject.METHODofSampleProxyClass();
How to Add Proxy class Object to Another View Object.
Not Possible to add and it does not have any impact actually when we think logically.
3:create the object of viewProxy class before calling there methods.
example:
var sampleProxyViewObject = template.createSampleView(); or
var sampleProxyViewObject = template.createSampleView({});
Note: "createSampleView()" here "SampleView" is the name used while creating viewProxy class and view class,
i.e. ComGlTemplateSampleViewProxy and view as ComGlTemplateSampleView.
Method Calling Example:
sampleProxyViewObject.METHODofSampleViewProxyClass();
How to Add ViewProxy class Object to Another View Object.
taking consideration that "windowObject" is already created and trying to add viewProxy Object in that.
example: windowObject.add(sampleProxyViewObject); Some Important Points to remember.
Note: Always call the view methods from the methods exposed in the viewProxy on MainThread else it will crash the application.
Note: ViewProxy object can be added to the Other View In titanium App But A normal proxy Objet can not.
Note: A Method with prefix "set" will receive the parameter directly while methods without "set" prefix will receive parameter as an NSArray Objet, single or multiple parameter does not have any impact on this behavior.
sampleProxyObject.METHODofSampleProxyClass();
How to Add Proxy class Object to Another View Object.
Not Possible to add and it does not have any impact actually when we think logically.
3:create the object of viewProxy class before calling there methods.
example:
var sampleProxyViewObject = template.createSampleView(); or
var sampleProxyViewObject = template.createSampleView({});
Note: "createSampleView()" here "SampleView" is the name used while creating viewProxy class and view class,
i.e. ComGlTemplateSampleViewProxy and view as ComGlTemplateSampleView.
Method Calling Example:
sampleProxyViewObject.METHODofSampleViewProxyClass();
How to Add ViewProxy class Object to Another View Object.
taking consideration that "windowObject" is already created and trying to add viewProxy Object in that.
example: windowObject.add(sampleProxyViewObject); Some Important Points to remember.
Note: Always call the view methods from the methods exposed in the viewProxy on MainThread else it will crash the application.
Note: ViewProxy object can be added to the Other View In titanium App But A normal proxy Objet can not.
Note: A Method with prefix "set" will receive the parameter directly while methods without "set" prefix will receive parameter as an NSArray Objet, single or multiple parameter does not have any impact on this behavior.
Hello Ashish ,
ReplyDeleteGood For Putting the Nice Article.
Hello Aashish, I have a question on View Proxy(iOS Module development), Could you please help me ?
ReplyDeleteI have a method in TiVIew. see below code
-(id)TestMethod:(id)args{
return @"TestMethod Method";
}
How to call this from its View Proxy Class? Titanium Doc explain only about void type method.. (see code below)
(void)show:(id)args
{
[[self view] performSelectorOnMainThread:@selector(show:)
withObject:args waitUntilDone:NO];
}
I'm fed up now.. please help me man
Hi, Mohamed... Sorry for being so late and i was not able to check my own blog and busy doing some other R&D.
ReplyDeleteso for you question... you can call any method of view from viewProxy.. but using the above approach you asked will not return you the value. thats why Doc explain you only about void methods.
if you want to get some value from view then, you have two options...
1: use the KrollDict and update the value there.. then after update call get the value in proxy.
2: for non UI component, call the method of View using normal objective C syntax.
Hi Ashish,
ReplyDeleteDo you know how to develop native module for Android, to use in Titanium. Can you post that too?
Hi Nadeem,
ReplyDeleteI am aware of Android Module development approach also and will share soon.
I just wanted to say thank you for putting this together, it has definitely helped my understanding of module development.
ReplyDeleteHI can i ask a question?
ReplyDeletein the module im developing i need to load one xib file and one .bundle
i want to place the bundle otuside the module ( i want place it in the titanium app resource folder) and load from module the xib file
i tried to load the xib with
self = [self initWithNibName:@"modules/it.scsoft.imgedit/_CLImageEditorViewController"
bundle:nil];
in the viewcontroller im using but it create error i also tried with
self = [self initWithNibName:@"_CLImageEditorViewController" bundle:nil];
same error, nib not found..
i have the same problem with the bundle file
can you help me? contact me at boardmain @ gmail . com if you can ( i can send you the module if you want)
regards
Hi Samuele, Is your issue resolved? i was busy in some other R&D and thus did not get time to look for other work. My Bad, please share more details so that i can try to help you.
Delete