Archive for July, 2010

iOS package for distribution with 1.4+

Tuesday, July 27th, 2010

There have been a few questions around how to package for distribution for iOS starting with Titanium SDK 1.4. Apple has changed the requirement on how you package and submit your application to iTunes connect. You can no longer use the web-based portal to upload your application.

I thought I’d explain the steps on how to package and distribute with some screenshot walk throughs.

In Titanium, you’ll do the normal package for distribution step, selecting your distribution profile.

NOTE: I have circled the “Select Distribution Location” since this is no longer required. In 1.4 SDK, we ignore this value. We didn’t want to rev Titanium Developer just to remove this field and to keep in backwards compatible. However, you will still need to enter a value for this field. In a future release of Developer, we’ll improve this.

After packaging, we’ll automatically start Xcode Organizer. Select the “Archived Applications” on the left menu and you should see your Application with a package date.

If you select the date, you will be able to enable the buttons at the bottom.

First step, you’ll want to validate your application. This will actually validate your application with Apple prior to submission and let them perform some pre-flight checks.

You’ll need to login to iTunes connect before you can validate. (The first time, you’re credentials will be empty. Subsequent times, if you check “Remember my…” if we remember).

After successful login, you’ll need to choose the appropriate application and profile. IMPORTANT STEP: If you don’t have an application setup in iTunes Connect (on the website), these subsequent steps SILENTLY FAIL.

NOTE: Organizer gives no visual clues to as what’s happening. The UI will lock-up while it runs network operations and when it fails, it simply does nothing and you have no idea. The biggest problem I’ve encountered is when someone doesn’t actually have an application setup (see above).

Choose your app and profile and you should see this alert result (after a few seconds to minute):

Since you’re building with Titanium, everyone should work. However, we’ve seen a few issues mainly related to the wrong size icon when validating. Apple has gotten more strict on icon sizes, etc.

To submit your application, click the “Submit Application to iTunes Connect..” button. BEWARE: when you do this, it will immediately upload your app and submit it for approval (assuming that your application details are setup).

At this point, your application should be submitted and in the queue for approval.

Introducing Titanium Mobile 1.4

Tuesday, July 27th, 2010

OK, so this release took way longer than we all anticipated. We tried our best working days and nights and weekends to make it faster, but sometimes this stuff just takes longer than you’d like. In our case, we ran into a lot of major issues with iOS4 and between the various devices, versions and permutations. There’s quite a bit of more work we intend to do starting tomorrow for 1.5 but we feel like this release is much improved over the 1.3.2 drop we did 2 weeks ago.

Thanks for everyone’s patience and assistance during this time. We fixed well over 200 reported bugs as well as worked through many many more we found in our own testing. There’s a lot of great improvements in this release and a few new things. The full release notes can be found on the documentation page for the release.

Next up is 1.5. We’ll be publishing more information about the next release once we’ve had some time to rest, review with the engineering, support and QA teams and write it all up.

We also have a bunch of new high quality documentation that will roll out soon, thanks to two of our newest members of our official Training team we added awhile back. We hope to have more information about that very soon. Stay tuned!

UPDATE (7/27 10:30PM ):

There’s a logging issue that Apple introduced with 4.0.1 that affects logging while running your app in the simulator.

You can get the hot patch for this by downloading this file (name it logger.py). Drop this into your /Library/Application Support/Titanium/mobilesdk/osx/1.4.0/iphone directory. Make sure that you chmod a+x the logger.py file to make it executable. No need to restart Titanium Developer. Just re-launch your app in the simulator.

Using Spazcore for Twitter Authentication

Friday, July 23rd, 2010

Today I wanted to call out one of the more interesting projects happening on Titanium Desktop, and show how you can leverage its core library in your own Titanium Desktop projects. The Spaz microblogging client is one of the most popular open source Twitter (and StatusNet and Identi.ca) clients available today, and developer Ed Finkler (follow him on Twitter here) is leading the Spaz project in a port of the desktop version from Adobe AIR to Titanium Desktop, and to eventually bring Spaz to iPhone and Android handsets via Titanium Mobile.

With the Spaz project already running on the desktop and webOS platforms, Ed wisely decided to separate out core logic into a centralized library which he calls Spazcore. Spazcore has many useful features which you can use today in your Titanium Desktop applications, not least among them a facility for making xAuth authenticated requests to Twitter through a nice JavaScript API.

If you haven’t tried implementing xAuth (or oAuth) in your applications, SPOILER ALERT: it’s not trivial. xAuth is a much better fit for desktop and mobile applications, since you are able to skip the browser re-direct song and dance and exchange a username and password for a token that you will use to authenticate subsequent requests. xAuth uses the same header information and request signatures used by oAuth, however, so you still have a fair amount of work to do as the developer to sign your API requests properly. Luckily for us, Ed has figured this out already and abstracted it out into Spazcore, so we can very quickly and easily create a desktop application which uses xAuth for authenticated access to Twitter.

Your first step is to create a Twitter application at dev.twitter.com and request xAuth permission from Twitter, a process described on their developer site here. Essentially, you will send an e-mail to the Twitter team providing information about your application (I had to provide some screenshots for one app as well). After a day or two, you will be notified that your app has been blessed to access Twitter via xAuth.

Next, create a Titanium Desktop application to test out your new Twitter xAuth creds. After your project is created, you’ll need to grab the JavaScript dependencies you’ll need for Spazcore, including the library its self and a version of jQuery, upon which Spazcore currently depends. If you’re running a system that has curl available on the command line (like OS X or many Linux distros), fire up a terminal window, navigate to the Resources directory of your new Titanium Desktop project, and execute the following commands to quickly download the necessary dependencies (or just download these files and manually copy them):

curl http://code.jquery.com/jquery-1.4.2.min.js > jquery-1.4.2.min.js
curl -L http://bit.ly/spazcore-tutorial > spazcore.js

As always, we have a Gist available here which implements a simple index.html you can drop in to your new project to see Spazcore authentication in action (the complete example, adapted from Ed’s Spazcore examples is embedded below the tutorial). I’ll quickly illustrate some of the high points of the Spazcore API:

Spazcore configuration and dependencies

After including the jQuery and Spazcore libraries via standard script tags in the head of your HTML document, we will declare some global variables that we will use when creating an authenticated Twitter session:

// Include Twitter configuration - your keys must be approved for xAuth.
// More info: http://dev.twitter.com/pages/xauth
var SPAZCORE_CONSUMERKEY_TWITTER = 'consumerkey';
var SPAZCORE_CONSUMERSECRET_TWITTER = 'consumersecret';

Adding the Twitter service to Spazcore

The next step is configuring Spazcore to use our oAuth credentials for a connection to Twitter:

SpazAuth.addService(SPAZCORE_ACCOUNT_TWITTER, {
  authType: SPAZCORE_AUTHTYPE_OAUTH,
  consumerKey: SPAZCORE_CONSUMERKEY_TWITTER,
  consumerSecret: SPAZCORE_CONSUMERSECRET_TWITTER,
  accessURL: 'https://twitter.com/oauth/access_token'
});

Creating an authorization “pickle”

As we mentioned before in our brief discussion of oAuth/xAuth, we are essentially exchanging a username and password combination for a token (or set of tokens, more accurately) that we can use to sign requests to to the oAuth provider (in this case Twitter) for subsequent requests for protected data (or to create/modify data on behalf of the user). Spazcore simplifies this process for us by accepting a username and password from our application, and allowing us to save our set of tokens as a simple string (called a ‘pickle’) that we can use for future authenticated requests:

var auth = new SpazAuth('twitter');
 
// result is a boolean indicating success of the auth request
var result = auth.authorize('someusername', 'somepassword');
 
// You can save this authenticated session in an authPickle string
// which contains access token information, not the actual username
// and password combo, for later requests.
var authPickle = auth.save();

Do the Twitter!

With an authorized token all set up, we are now ready to talk to Twitter. To do this, we will create an instance of an object called SpazTwit, which implements an API we can use to execute various functions against Twitter. There aren’t any docs for SpazTwit that I could find (read on after the tutorial to see how you can help with that), but you can inspect the API in the source code (which is commented well enough to get the gist of what’s going on). The SpazTwit implementation starts at about line 11122 of the uncompressed Spazcore library I had you download – the interesting bits for the external API start getting added to the SpazTwit prototype at about line 116356. In the example below, we will grab the home timeline (which would normally appear on the web at http://twitter.com/yourusername):

// Load OAuth from the serialized string we got earlier 
// (or maybe we saved it in a database or property):
var auth = new SpazAuth('twitter');
auth.load(authPickle);
 
//Create a SpazTwit instance with the auth data we have
var twit = new SpazTwit({'auth':auth});
 
//Make a Twitter API call!
twit.getHomeTimeline(null, 200, null, null, function(timeline) {
  //do something with the results of this call
}, function() {
  //do something if there is an error!
});

Here is the full example in action:

Give Back!

Ed, like every good, long-suffering open source maintainer, does a lot of the heavy lifting for Spaz himself and could use your help. If you end up using Spazcore, please consider contributing either source code, documentation, or moral support to Ed as he continues his development efforts. Like us at our own #titianium_app channel, Spaz contributors and users often hang out on IRC at irc.freenode.net in the #spaz channel. Here are some of the other places where you can find further information on the Spaz/Spazcore project, and hopefully help out yourself:



Also, you can reach out to Ed directly and follow his exploits on Twitter. As promised, the fully functional example app is included below. Big thanks to Ed for this library, and hopefully it will be of use on your next Titanium Desktop project!

Titanium at OSCON 2010

Wednesday, July 21st, 2010

Recently, I was lucky enough to give a Titanium tutorial at the 2010 O’Reilly Open Source Convention (and take in several other interesting talks). It’s a really cool event and Portland/the Oregon Convention Center combine for a great venue. I gave a ~3 hour tutorial on building native apps in Titanium, and I’ve posted my slides for the tutorial if you’re interested in checking them out. We had well over 100 people in attendance at one of the convention ball rooms – it was great to see such a high level of interest in Titanium. Slideshare munged my fonts a bit, but it’s still very readable:

I also had some time to talk to some bloggers and the good people at O’Reilly. A few interviews have been posted online, including this piece at the Girls In Tech blog (reposted at Ivo’s blog). It was great to introduce so many developers to Titanium – thanks to those that were there, and I hope you’re enjoying OSCON!

Twitter oAuth Implementation for Titanium Mobile

Friday, July 9th, 2010

We have a great community project to highlight today – David Riccitelli (follow @ziodave on Twitter here) has developed a pure JavaScript oAuth helper library for Titanium Mobile (today it’s iPhone only, but if you check out source on Google Code I’m sure one of us can rectify that).

If you’d like to use it, your first step is to register your application at Twitter’s developer site. Once you do that, you should be able to grab your application’s consumer key and shared secret:

Once your app is set up, you’re ready to integrate David’s Twitter library. Create a new Titanium Mobile project, and under the Resources directory, create a /lib folder. In this directory, you will place the required JavaScript files for David’s library – all three files are linked from David’s guide:

Your next step is to integrate Twitter for fun and profit! In app.js, drop in the following code to see a simple example in action:

var oAuthAdapter = new OAuthAdapter(
        '<your-consumer-secret>',
        '<your-consumer-key>',
        'HMAC-SHA1');
 
 
// load the access token for the service (if previously saved)
oAuthAdapter.loadAccessToken('twitter');
 
oAuthAdapter.send('https://api.twitter.com/1/statuses/update.json', [
  ['status', 'hey @ziodave, I successfully tested the #oauth adapter with #twitter and @appcelerator #titanium!']
], 'Twitter', 'Published.', 'Not published.');
 
// if the client is not authorized, ask for authorization. 
// the previous tweet will be sent automatically after authorization
if (oAuthAdapter.isAuthorized() == false) {
    // this function will be called as soon as the application is authorized
    var receivePin = function() {
        // get the access token with the provided pin/oauth_verifier
        oAuthAdapter.getAccessToken('http://twitter.com/oauth/access_token');
        // save the access token
        oAuthAdapter.saveAccessToken('twitter');
};
 
    // show the authorization UI and call back the receive PIN function
    oAuthAdapter.showAuthorizeUI('http://twitter.com/oauth/authorize?oauth_token=' +
        oAuthAdapter.getRequestToken('http://twitter.com/oauth/request_token', [['oauth_callback', 'oob']]),
        receivePin, PinFinder.twitter);
}

You’ll find that once you have signed in once to Twitter, you will be able to successfully update your stream without re-authorizing, as David is storing your authorization token locally. Very cool stuff, thanks David! David also recently published this quick video demonstration of his Twitter library in action in his own (also cool) Titanium app, which is embedded below. Please show David some love for his very useful contribution!

Twitter OAuth in Titanium from David Riccitelli on Vimeo.