Titanium Dictionary Module

What to use the native iOS5 Dictionary in your Titanium Mobile app?

The new benCoding.Dictionary module that makes it easy to this functionality into any Titanium app that targets iOS5 or greater.

Want to download the module?

You can download the compile module here.  Please take a look at the “Before You Start” section to make sure you have all of the module dependencies.

Interested in the source?

The source is available in the benCoding-Dictionary repo on GitHub.

Before You Start

This module has a few dependencies, make sure you meet the below criteria.

  • You need to be targeting Titanium 1.8.1 or greater.
  • This module requires iOS5

How Does It Work?

The module provides a Titanium wrapper around Apple’s native UIReferenceLibraryViewController.

What Does It Look Like?

Since this is largely a UI component please find below a short video showing the example app running in the simulator.

Documentation & Examples

For the example app shown above and full html documentation please check out the documentation and example folders in the module zip.

Need A Quick Example?

Here is a quick example showing how to use the module.  To learn more please see the documentation link here and the example link here.


var referenceLibrary = require('bencoding.dictionary').createReferenceLibrary();
Ti.API.info("This feature is only supported in iOS5 and above");
Ti.API.info("Check if we have the min OS version needed");
Ti.API.info("Is Supported? => " + referenceLibrary.isSupported());
Ti.API.info("Check if Apple knows the definition for fanboy");
var hasDefinition = referenceLibrary.wordHasDefinition('fanboy');
Ti.API.info("Term has definition =>" + hasDefinition);

if(!hasDefinition){
alert('You can still call showDialog it will just display a message that no definition was found');
}else{
//If you want you can define some callbacks
function termDialogBoxHasBeenClosed(){
Ti.API.info("I'm a callback when the Definition Dialog Box has been closed.");
};
function termDialogHadError(e){
Ti.API.info("I'm a callback when an error happens this error is due to: " + e.error);
};

Ti.API.info("You can add an event to be called if there is an error");
referenceLibrary.addEventListener('errored', termDialogHadError);

Ti.API.info("You can add an event to be called when the definition dialog is closed");
referenceLibrary.addEventListener('closed', termDialogBoxHasBeenClosed);

//Open the definition dialog window
referenceLibrary.showDialog({
//This is the term to search for (REQUIRED)
term:'fanboy',
//Indicate if the dialog should be animated on open (OPTIONAL)
animated:true,
//This is the transition style (OPTIONAL)
modalTransitionStyle:Ti.UI.iPhone.MODAL_TRANSITION_STYLE_FLIP_HORIZONTAL
});
}
About these ads
10 comments
  1. ajeet said:

    This is what i was looking for- how to show a viewController from any extended iOS module..Great and awesome work….

  2. ajeet said:

    I didnt get the line “var referenceLibrary = require(‘bencoding.dictionary’).createReferenceLibrary();” what is createReferenceLibrary doing there. what if i just want to show a ViewController how to do that…

    • benbahrenburg said:

      Hello,

      The line “var referenceLibrary = require(‘bencoding.dictionary’).createReferenceLibrary();” creates a new instance BencodingDictionaryReferenceLibraryProxy which is the Titanium Proxy object that makes the methods on the UIReferenceLibraryViewController callable from Titanium. This also acts as a bridge layer where you can insert any Titanium specific behaviours.

      Alittle about Titanium Modules:
      To make any native objects available to Titanium you need to create a proxy object. For views, you need to create what is called a view proxy. You can read more about this here

      There is a great tutorial project available here

      I’ve got a few more modules in the works you can view at once I’ve finished the examples and documentation I’ll be posting more details.

  3. ajeet said:

    Thanks for the explanation… So if we create an module which is extended in iOS, and in the module i have many view controller, so for each viewController i will be having different viewProxy ?

    Can you recommend a nice tutorial where a simple ViewController is called from module is called by Titanium App.

    and one more thing your “here” link is not clickable… :)

  4. ajeet said:

    Hey Ben,
    your new post regarding the sms module opened my mind regarding my question above..
    Will try to implement and if faced any difficulty will contact you..

    And very nice stuff “SMS module” loved it..:)

  5. ajeet said:

    Hi Ben as you said that “var referenceLibrary = require(‘bencoding.dictionary’).createReferenceLibrary();” creates a new instance BencodingDictionaryReferenceLibraryProxy”.

    As my module name is “ComAjeet” so i named my proxy as “ComAjeetMyDialogProxy” and when i tried to do the following:

    “var myModule = require(‘com.ajeet’).createMyDialog() ;” it gives me error while running the app as: “invalid method (createMyDialog) passed to comAjeet Module at app.js what i am missing here

    • HI Ajeet, please contact me on twitter @benCoding with a link to github and I’ll take a look.

  6. Hi Ben,

    Thanks a lot for putting together this module. I’ve been having some issues though:
    I keep getting an Unlicensed Module error when trying to include this module in my application. Any idea what might be causing this? I’m currently using another module without issue.

    The other module I’m using (ti.box2d), I’m actually building from source, so I thought that building this module from source might fix my problem. However, when I clone the source and try to build, I get the following error:

    fatal error: ‘TiModule.h’ file not found [2]
    #import “TiModule.h”

    The box2d module I’m using also imports this file, but doesn’t have any trouble finding it.

    Thanks for your help!

    • Hello,

      I put the module into the marketplace, most likely that is the licensing issue you are running into. I’m working on trying to find away around it at the moment. For now the easiest way to do this is to go to https://marketplace.appcelerator.com/apps/1918 press the download button. That should fix any issues with download the compile from the releases folder.

      For the issue issue, with the missing header, please take a look at your titanium.xcconfig file.

      Mine looks like:
      TITANIUM_SDK = /Users/benjamin/Library/Application Support/Titanium/mobilesdk/osx/$(TITANIUM_SDK_VERSION)
      TITANIUM_BASE_SDK = “$(TITANIUM_SDK)/iphone/include”
      TITANIUM_BASE_SDK2 = “$(TITANIUM_SDK)/iphone/include/TiCore”
      TITANIUM_BASE_SDK3 = “$(TITANIUM_SDK)/iphone/Classes”
      HEADER_SEARCH_PATHS= $(TITANIUM_BASE_SDK) $(TITANIUM_BASE_SDK2) $(TITANIUM_BASE_SDK3)

      You will need to update the TITANIUM_SDK path to file your own environment. Depending what version of OSX your using this could be different.

      If you have any other questions let me know.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 1,076 other followers

%d bloggers like this: