Monday, 5 May 2014


Titanium Module Guides and Tricks : 



TiModule.h' file not found:
 

you need to edit your titanium.xcconfig TITANIUM_SDK to reflect your path...
most commonly the needed change is from the defaul:

TITANIUM_SDK = /Library/Application Support/Titanium/mobilesdk/osx
               /$(TITANIUM_SDK_VERSION)

to:

TITANIUM_SDK = ~/Library/Application Support/Titanium/mobilesdk/osx
                /$(TITANIUM_SDK_VERSION)
 
 
 

Adding Special Compiler Directives in module.xcconfig :  

If your module needs a special Framework or other system library or special compiler directives, you can use the module's xcconfig file to define them. Titanium automatically creates a file named module.xcconfig and one named titanium.xcconfig. The titanium.xcconfig is used when compiling your module for packaging. However, module.xcconfig is used by the application compiler when the application is built and your module is referenced. This allows you to control the compiler directives used during this process, too.

First, we'll need to add the Framework in Xcode. In this example, we'll simply add GameKit. Select Frameworks in your project folder, right click "Add -> Existing Frameworks" and select the menu item And choose "GameKit.framework" and click the "Add" button. You should now see the new Framework reference under the Frameworks folder:

If you compile your project, you should now have no errors.

Now that we've added the Framework to the project, we still need to set it up so that the application compiler can also import this Framework during compile. To do that, edit the module.xcconfig and add the following line at the bottom:

OTHER_LDFLAGS=$(inherited) -framework GameKit

If we have number of Frmework in the module then you can edit the module.xcconfig and add the following way :

OTHER_LDFLAGS=$(inherited) -framework AddressBook -framework AddressBookUI -framework UIKit -framework Foundation -framework CoreGraphics

 

Adding Library in module.xcconfig :  

Framework Can be added by above way in module.xcconfig file , but what I really wanted to know was how to set path subproject library file such as "xxxx.a" and header "xxx.h". First i built it as one project, but it was hard to set path header when i package it by "builder.py". Now I solved this problem. I changed like the following. :

I built subprojects each and then get the header and lib(.a)file each.
Then just added those titanium module project in XCODE. Then, set path Header search path in XCODE's Building Setting.

I built subprojects each and then get the header and lib(.a)file each. Then just added those titanium module project in XCODE. Then, set path Header search path in XCODE's Building Setting.

Also added path such as .dylib in module.xconfig like this.  :

other_ldflags = $(inherited) -framework CFNetwork /usr/lib/libiconv.dylib

eg) CFNetwork is framework, libiconv.dylib is usr/lib libarary file.

 

Adding fireEvent in Module and Catch in Titanium: 

 

 testModule.m

#pragma Public APIs
-(id)example:(id)args
{
    if([self _hasListeners:@"addProgress"]){
        NSLog(@"[INFO] firing from iOS method ==> -(id)example:(id)args");
        [self fireEvent:@"addProgress"];
    } else {
        NSLog(@"[INFO] Not firing..1");
    }
    // example method
    return @"hello world.....";
}

index.js from Titanium

// TODO: write your module tests here
var test = require('com.test');
Ti.API.info("module is => " + test);


test.addEventListener("addProgress", function(e) {
    Ti.API.info("addProgress from Titanium");
    alert("Event Fired!");
}); 


You can refer below links for module :
  1. http://www.slideshare.net/omorandi/ticonf
  2. http://developer.appcelerator.com/question/51751/how-to-fire-an-event-in-a-module-and-catch-it-in-js

 

 

 

 


 

2 comments:

  1. All the contents you mentioned in post is too good and can be very useful. I will keep it in mind, thanks for sharing the information keep updating, looking forward for more posts. Thanks
    xamarin app development

    ReplyDelete
  2. Thanks for giving knowledge Excellent overview :)
    android developer USA

    ReplyDelete