Archive for September, 2010

Titanium Mobile 1.4.1 (for OSX only)

Monday, September 20th, 2010

We have pushed a patch release (named 1.4.1.1) for OSX only. If you’re not on OSX, you won’t get an update notification.

This release contains two small fixes that have been caused a little bit of a problem for new users:

- iTunes 10 issues which “Loading…” message in the SDK field under Titanium Developer simulator/test/package

- Apple 4.0.x logging issues

One known issue for the iOS 4.1 SDK is that you might see something like the following in the console:

mmap$UNIX2003 called from function _Z20TCMalloc_SystemAllocmPmm

We’re going to try and fix that warning for the 1.5 release but this is harmless and has no impact on your application (as scary as it looks).

We are still working on the 1.5 release and hope to get to a final code freeze very soon and begin full testing. Our Quality goals for the 1.5 release are much higher and so I anticipate that it won’t be available until March October (edit: what was I thinking?).

We’ll have more details about this release soon. In the meantime, this release has significant performance and functional improvements in Android and internally we’re calling this our “Android release” given how much effort is going into this release for Android. Not that iOS is getting the shaft, we have plenty of fixes and great work on that platform too.

If you have installed from github since 1.4.0, please note that you will not get an update in Titanium Developer until you remove your 1.4.0 directory. Also, not that we have moved the build version to 1.4.2 in master This does not mean that the next release is 1.4.2, it’s simply a way to not cause issues if you install a build from master with the upcoming 1.5 release.

(EDIT: after testing and push to distribution, we found we included the wrong lib. we’re re-pushing as 1.4.1.1 with the correct lib).

Titanium Module API uploaded as a PDF

Friday, September 17th, 2010

We’ve put together a PDF covering the Titanium Module, containing the Titanium Mobile 1.4 APIs. This is the same information that continues to be available on-line, just organized as a single document that you can use offline. Depending on the capabilities of your PDF reader, you can use the PDF navigation links to move around in the document, and of course you can search. You’ll probably find that this works better in a PDF reader than in a browser.

You’ll find a link to this on our API Documentation page.

The margins are tight — if you want to print it, be sure to tell your PDF reader to print the full image of each page, which might require a slight reduction of the layout as it’s printed.

This is an experimental document at this point. There are some formatting issues, and we’re working to improve them. In the meantime, I hope this is useful. Please let me know how this works out.

Database API Reference Guide updated

Wednesday, September 15th, 2010

Check out the updated Titanium Mobile API Reference Guide for Database — there are some new code samples to help get you going.

One of the new examples shows how to store and retrieve a blob using the SQLite database. The blob datatype is pretty useful — in this example, it’s a very general datatype that stores an image. Suppose you have a JPEG image called 'myphoto.jpg' in your Resources directory. Let’s look at how you would read the image from the file, and then add it to the database.

var imageFile = Titanium.Filesystem.getFile('myphoto.jpg');
var oneImage = imageFile.read();

The above code will read the image from your JPEG file, and store it into the oneImage variable.

Now let’s see how you could store images into a database. First, we’ll open a database file and create the database table using an SQL command.

var db = Titanium.Database.open('images');
db.execute("CREATE TABLE IF NOT EXISTS pics (id INTEGER, image BLOB)");

Now that we have the database table, let’s insert our photo:

db.execute("INSERT INTO pics (id,image) VALUES(?,?)", 1, oneImage);

This inserts a row into the database table, with id equal to 1, and image containing the image as a blob. When it comes time to retrieve the image from the database, you’ll use code something like this:

var myResultSet = db.execute("SELECT * FROM pics");
if (myResultSet.isValidRow()) {
    retrievedImage = myResultSet.field(1);
}
myResultSet.close();

This will select all the rows from the database table, and set your retrievedImage variable to the image blob in the first row. At this point, you can do whatever you’d like with the image — you could display it in an ImageView, for example.

However, there’s a potential problem with the technique shown above. Depending on the size of your database table, the SQL command we used to select every row could return a result set that has many rows, and many images. This could take an unacceptably large amount of memory. So an improved technique would be to figure out first which image you need, and then select only the corresponding row(s). Here’s a modified SQL statement that selects only the first row in the database table:

var myResultSet = db.execute("SELECT * FROM pics WHERE id=1");

If you need to store pictures in your application, you should consider whether the database is the right solution. For most picture-taking applications, a better approach would be to store the pictures as files in memory, or on the memory card, and then use the database to store the names of those files.

You can see the complete sample app in the Titanium Mobile API Reference Guide for Database. Happy coding!

In the clear: Apple opens up iOS to all developers

Thursday, September 9th, 2010

Dear Titanium Community -

This morning, Apple issued a positive clarification to its terms of service that relaxes its restrictions on the development tools used to create iOS apps.  We believe this provides a strong endorsement for developer innovation, reinforces Apple’s long-term platform advantage, and benefits consumers as the ultimate arbiters of quality in the App Store.  Obviously, we’re incredibly pleased with this decision and we look forward to the innovation that Appcelerator Titanium developers will continue to bring to the Apple App Store.

To be clear, this morning’s announcement effectively removes any remaining concerns regarding app approval and Appcelerator Titanium.  Today, over 67,000 web developers have built approximately 4,000 native mobile applications using Titanium and this number is growing at a rapid pace of over 1,000 per month.  Major brands such as NBC, eBay, MTV, Budweiser, and Jaguar are choosing Titanium as their platform of choice to build native mobile, desktop, and iPad applications.  As well, chart-topping applications that you have developed such as GetGlue, Terminology, My Newspaper, and others showcase how web developers can build high-quality applications that consumers are embracing by the millions.

On behalf of all of us at Appcelerator, I want to personally thank each of you for your support over the past few months.  Your feedback has helped us get Titanium to where it is today and your perseverance through this period has demonstrated the strength of character that our entire developer community is built on.

As always, please let us know how we can continue to help in your development efforts.

Code Strong,

Jeff

Different ways Titanium can do the same thing

Tuesday, September 7th, 2010

This article illustrates how Titanium often provides several different ways to accomplish the same result. The first examples involve a TableViewRow object’s properties, and the second shows different ways that rows can be added to a TableView. The choice among these different techniques depends on what your application does, and how it’s structured. Comparing these patterns will help you understand more about Titanium.

Most objects in Titanium have properties that change the behavior of the object in various ways. There are many properties associated with the TableView object, and the related TableViewRow and TableView Section objects. For example, some of these properties are the title, color, and opacity — and there are different ways to set these values.

In these examples, we’ll use the title and color properties of a TableViewRow. The first example of setting properties is to include them in a dictionary object when you create the TableViewRow, like this:

var myRow = Titanium.UI.createTableViewRow(
                          {title:'Carrot juice', color:'#FF6600'});

This code creates a TableViewRow object, specifying the string ‘Carrot juice’ as the initial value for the title, and sets the color to a shade of orange.

Now let’s create the TableViewRow as before, but we’ll set the properties after the object has been created:

var myRow = Titanium.UI.createTableViewRow({});
myRow.title = 'Carrot juice';
myRow.color = '#FF6600';

This example does exactly the same thing as the first one. The only difference in the second example is that the TableViewRow object is created first, and then the values for the title and color properties are added later. You can use this technique to change the properties of an existing object, perhaps in response to some user-generated event, like this:

myTableView.addEventListener('click', function(e) {
    if (e.index == maxRow) {
        lastTableViewRow.color = '#3399CC';
    }
});

This event listener checks to see if there was a click on a row; if there was, it changes that row’s color if it is the last row.

Now let’s look at how we might create a TableView object that has several rows. Again, Titanium offers different ways to accomplish the same thing. For our first example we’ll create a TableView with 4 rows, using an array that we’ll pass to the createTableView method:

var myData = [{title:'Coffee'}, {title:'Tea'},
                             {title:'Juice'}, {title:'Ice water'}];
var myTableView = Titanium.UI.createTableView({data:myData});

Notice that during the createTableView method, the data property is set to the array of data that we created. Titanium uses the data in that array to build the TableViewObject and its rows, one row for each element in the array. But you can also append a row to an existing TableView object using the appendRow method, like this:

var myRow = Titanium.UI.createTableViewRow({title:'Hot chocolate'});
myTableView.appendRow(myRow);

You can use this approach to programmatically create a TableView row by row. This could be handy, for example, if you were taking the row titles from a database.

Another approach is to use a TableView’s setData method if you want to completely replace the TableView data. You call setData like this:

// Create 2 sections, and add a row to each
var hotTableViewSection =
        Titanium.UI.createTableViewSection({headerTitle:'Hot beverages'});
hotTableViewSection.add(Titanium.UI.createTableViewRow({title:'Coffee'}));
var coldTableViewSection =
        Titanium.UI.createTableViewSection({headerTitle:'Cold beverages'});
coldTableViewSection.add(Titanium.UI.createTableViewRow({title:'Juice'}));
 
// Create the TableView and then use setData
// to apply the new data to it, resulting in the 2 sections
var myTableView = Titanium.UI.createTableView();
myTableView.setData([hotTableViewSection, coldTableViewSection]);

Whichever approach you use, you’ll end up creating a TableView and its rows. Choose the pattern that works best for your application.

You can find more comprehensive documentation in the API Reference Guides for Titanium.UI.TableView and Titanium.Database, along with more complete sample code.