Tuesday, July 3, 2012

Mobile Apps: Saving user preferences (Titanium only)

I am passionate about mobile apps and one of my favorite mobile app development toolkit is Titanium by Appcelerator.

Often mobile apps need to save user preferences such as font size and such. As I dug around, I found some interesting posts and built upon them, I figured it may be worth sharing it. So, here is one way of storing user preferences using Properties

1 2 3 4 5 6 7 8 9 10 
//Created for http://www.blog.iSl8.com

//This code checks to see if there is a user preference set, otherwise, it sets the default preference property.
if (Titanium.App.Properties.getString('MyCustomPreference1') != null){
Ti.API.info('Custom Preference 1 was already set to ' + Titanium.App.Properties.getString('MyCustomPreference1'));
}
else { //Set default Custom Preference 1
Ti.App.Properties.setString('MyCustomPreference1', 'Default Preference1 value');
Ti.API.info('The Custom Preference 1 was defaulted to : ' + Titanium.App.Properties.getString('MyCustomPreference1'));
}

Then, where ever I needed to access it, I just used the getString method.

Why not use Global variables instead?
When I initially started, I thought that is what I should do. Save or default it to a property, and the first time my code accesses this property, just copy it into a Global variable, which can be referenced in any file across the App.

For some reason, the getString code seems cleaner (as in more explicit) to me. That way, if someone changes this property using the setString method, they know exactly what they are changing, instead of some proxy Global variable.

Also, I am not a JavaScript Guru, but I would imagine that setting a property is internally just doing that anyway.

Happy Coding!

Saturday, February 25, 2012

HTML5 Mobile Apps builder - Easy-Peasy-Tiggzi

After writing some code with PhoneGap and Sencha Touch / jQueryMobile, I found myself wanting an easier solution especially to consume REST APIs.

<rant>In fact, consuming a REST API for Parse.com(A PaaS / hosted MongoDB instance) from an HTML5 application found me writing a custom Phonegap plugin / extension for Parse.com (which one of these days will probably find its way to Github).</rant>

Thus, on one of those "There's got to be a better way" whims, I was looking around for an easier way to make a basic business apps that can read / write (CRUD) data to a cloud server.

Tiggziui

And late one night, I stumbled upon Tiggzi which is a hosted solution that allows you to create mobile apps inside a browser using jQueryMobile UI controls and easily integrates Rest APIs for mobile backends.

Using Tiggzi (and following this video), I was able to create an app that reads QR codes and writes that data to Parse.com (a mobile PaaS back-end, ) in just a few hours.

Tiggzi_emulator

So, here are my thoughts...

Pros:

  • Easy to work with, no IDE / configuration / Android / iOS SDK required for basic prototyping
  • Very easy to integrate bar / QR code reader and to consume REST APIs,
  • Testflight style remote app deployment and testing (probably the coolest feature of this service)
  • Prompt support

Cons / Limitations:

  • Needs better documentation / more content on best practices etc.
  • Some UI controls are a little bit unintuitive
  • Takes a little getting used to (esp. for folks used to of typical IDEs, like me)
  • Will costs real money for making non-trivial apps

Here is the data on Parse.com (The bar / QR codes were read from products / QR generators using an Android phone and written to Parse.com).

Tiggzidatainparse

And here is the same data inside the emulator.

Tiggzi_parsedata

 

Summary: Tiggzi is an interesting way to make basic read / write mobile apps, and for a simpler business app it certainly deserves consideration.

However, for apps that need a superior UX (higher visual and interaction fidelity) and a tighter device integration / better performance, Tiggzi may run into the limitations of jQueryMobile controls and constraints of Phonegap itself.