IPhone


5
Sep 10

iPad Multi-Touch – in Javascript.

ipad_touches_small.jpg

I recently came across a nice article/experiment from Matt Gemmell (@mattgemmell) where he decided to test how many simultaneous touches the iPad Multi Touch display would register, it turns out its 11 and he put together a pretty impressive demo app to prove it (see the Screen Shot).

At first sight you would think its a pretty complex application to achieve this, i mean all the multi touch stuff and the animation seems quite complex, however anybody who knows the iOS SDK will tell you that this stuff is trivial at best, and while Matt has done a great job of pulling it all together its far from complex.

The SDK that wasn’t mean’t to be

This application got me thinking about the iOS SDK and the fact that Apple originally didn’t want us writing native applications and in fact they wanted us to write Browser based applications in Javascript, HTML5 and CSS3.

Now its pretty clear to me that the native apps we see (in abundance) on the app store like Angry Birds, Twitterific, Pulse, Things, Pages, etc… could be written using JS, HTML5 and CSS3 but they would most definitely be poorer for it, come on, the runtime performance, the slick User Experience, simply can’t be replecated to the same level with an app running inside a Browser! (let the flame war begin)

So on that note i decided to replicate Matt’s Multi Touch application in Javascript, HTML5 and CSS3, so with a little digging around in Apples documentation I found all the Javascript events that expose touches (touchstart, touchend and touchmove) and began hacking!

Now let me say right now that this is one hours worth of hacking and the end goal was to build an application that was comparable to Matt’s, I suspect some of the code could be optimised, in fact I really hope that is the case when it comes to the Canvas drawing methods (but that is another story for another post).

multitouchtest.pngNow for some reason I fully expected the JS version to respond to less touches than the native version but in fact its 11 just like Matt’s Version, I also expected the animation to be less “smooth” and jerky when I was moving my fingers around, and I was spot on. The iPad benefits from multithreading and a graphics rendering pipeline, where the Browser that my app is running in does not so any processing I do to draw, calculate or respond to touch events all happens in the same thread as well as the browsers rendering code, this in a nut shell is the reason why these apps will not compete with Naive apps, I may in the near future re visit this topic and look at using HTML5 Web-Workers which in theory would give me the ability to run background threads, but i suspect that even that wouldn’t help too much for applications that are so closely coupled to the rendering engine.

Anyway, here is the application I wrote (visit it on an iOS device) it works almost exactly like the Original albeit its not as smooth. The source code is all inline (for your convenience) so feel free to take a look (lift, steal, optimise, laugh at, etc…) and let me know what you think.

My Conclusion

The iPad really is a “Magical” device, and with Great tools like Sencha Touch web developers are better placed than ever before when it comes to building native-ish applications, but I really believe that these apps will be the poorer relations to their native cousins. So keep learning Obj-C folks!


20
Oct 09

How to respond to the IPhone Shake Gesture

The IPhone 3.0 SDK includes support for detecting when a user “Shakes” the IPhone, this is intended to be a usability feature allowing app developers to implement Refresh or Read All functions on shake, wow those crazy guys at Apple really do know how to innovate!

It’s pretty easy to implement all you need to do is register your view controller as the first responder and listen for the motion event.

-(void) viewDidAppear:(BOOL)animated{
	[super viewDidAppear:animated];
	[self becomeFirstResponder];
}

Once your controller is the First Responder you can receive the motion event like so:

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
	if (motion == UIEventSubtypeMotionShake)
	{
		refresh;
	}
}

This will work beautifully but you will however notice that any views you present over this one will not respond to all touch events, for instance the keyboard will not show when you touch a text field, this is because you need to resign the First Responder before you present the view like so:

- (IBAction)showMyCustomView {    
	[self resignFirstResponder];	
	[self presentModalViewController:myCustomViewController animated:YES];
}

As you can see this is all pretty easy and the only gotcha is the First Responder stuff, which also is pretty trivial.

Enjoy and please people, Shake Responsibly!


24
Aug 08

IPhone 3g is not water resistant!

Yesterday evening i spent a couple of hours sitting in my garden reading while the summer evening sun rained down. It was one of those peaceful moments where time seemed to stand still.

This morning when letting the Dog out to do what ever it is she does first thing in the morning, i took a stroll down the garden to reminisce about the night before only to realize that i had left my IPhone 3G on the hammock.

The sun that had blessed us the night before had been replaced by Rain and the IPhone was soaked! Needless to say, it doesn’t switch on any more and I’m gutted!

Fortunately i still have my old IPhone 2G so i can use that, but every time i look at it, it reminds me of my drowned little baby that was only a few months old :-(

Oh well life goes on, I’ll get the insurance company to send me a new one tomorrow ;-)


20
Aug 08

Daily Dose #4

Bourbon Creams and Bananas are not a balanced diet.

Phusion Passenger on Amazon EC2
Some useful stuff relating to Phusion Passenger (mod_rails) on Amazons Elastic Computing Cloud.

Moving from Java to C#
A senior ThoughtWorker talks about his first C# project 10 years after he first tasted the Java bean.

IPhone GUI PSD
Some photoshop goodies for mocking up IPhone UI’s.


14
Aug 08

Daily Dose #3

More estimating today! Calculating velocity tomorrow… Joy!

Y Combinator’s Demo Day Summer 2008
Some y-combinator startups show of there stuff.

YUI 3 Preview
Personally i prefer ExtJS but more choice in this area is good for all.

AppStore Developer TapTapTap Publishes Sales Figures
Interesting stats from TapTapTap – Makes me think I should building IPhone apps ;-)


12
Aug 08

Daily Dose #1

A few links to get us going…

IPhone Development

iphone-universal
Normalized CSS & HTML framework to develop iPhone webdev applications

C#

Simple REST Client
Some .NET code for consuming RESTful web services.

Rails

Understanding Map and Reduce
Some underused collection functions in Ruby

OS X Utils

Expandrive
Cool app that allows you to mount a sFtp folder.

MarsEdit
Powerful Blog Publishing For Your Mac.