Archive for the ‘Development’ Category

WWDC 2009 Keynote Reaction

Monday, June 8th, 2009

Today was the keynote for Apple’s Worldwide Developers Conference 2009. This is an event where traditionally all the new product releases and skunkworks projects underway by Apple are revealed to the world for the first time. Sometimes these events are landmark, such as with the announcement of the iPhone a couple years ago. Sometimes they’re more about incremental improvements to software and hardware, as was the case today. Nearly always, however, they’re exciting news for everyone who likes Apple hardware and software.

Today they made several announcements relevant to web and mobile developers. For starters, Safari 4 is finally out of beta. This is great because it means a faster browser will begin making its way into the hands of users and new features will begin to open up to developers (for example DOM storage).

Last but not least were the iPhone announcements. As expected, iPhone OS 3.0 will now make its way into the hands of customers with over 100 new features for developers and users to drool over, like cut/copy/paste, improved map API’s, more flexible developer API’s, undo support, an improved mail application, and more. On the consumer side, a HUGE new feature (and one that really shocked me actually) is native Internet tethering! This means you can use the Internet connection of your phone on your laptop PC. Another interesting improvement is the integration of a new version of Safari supporting HTML 5 internet streaming of audio and video.

The new “Find My Phone” feature is interesting. If you’re a MobileMe user and you lose your phone, you can log onto a website and it will show you on a map where the phone is. Great if you left it at the bar, but not so helpful if its in your slipper in the broom closet. However it does let you send your phone a message which will cause it to play a special alert, allowing you to track it down in your apartment. Like some ThinkPad PC’s it also supports a remote-wipe feature if your phone is really lost or stolen.

A big thing for application developers is the new In-App Purchase capability. But this is just another one of many new developer features like peer-to-peer connectivity, push notifications, Bluetooth programmability (paving the way for custom bluetooth accessories) among others.

Apparently Apple has opened up the maps restrictions, allowing turn-by-turn direction applications. This is big for custom app developers, but it remains to be seen how this will work with the limitations of the hardware itself.

Speaking of hardware – now for THE BIG NEWS. As expected Apple announced a new hardware spec for the iPhone (called the iPhone 3GS with the S standing for Speed -gong!). This phone is faster and better in just about every way. On an API side it will support OpenGL ES 2.0 (meaning I can finally use that book I bought). It will also have a killer camera app (with tap to focus capability) and a 3MP camera. You can even take video and edit the video right on the phone (works a bit like iMovie). The new phone will offer between 2 and 3x speed improvements for apps (the examples they used were mail, SimCity, and Preview). The phone will also have voice control, letting users call people or bring up apps just by speaking to the phone.

The new phone will have digital compass, although I’m not entirely sure how this would help me. I guess it’s good for mapping applications, or if I need to face Mecca for some reason. The new phone will also have data encryption which is great for business and government users. For battery life, we’re talking up to 9 hours of internet surfing, 10 hours of video, 30 hours of audio, 12 hours of 2g talk-time, 5 hours of 3g talk-time. Although if we are to base anything on the numbers given for the 3G iPhone, those are probably exaggerated. Bottom line is that battery life appears to be improved about 30%.

As for versioning, it looks like Apple will be keeping the current 3G iPhone as the ‘budget’ option for $99. Kindof a pain for developers, mind-you.

The bottom line here is that Apple has once again moved the bar forward, and put immeasurable pressure on competitors like Palm, Nokia, Microsoft, and Blackberry, and by-proxy Google to keep up on both a hardware and software front. From a developer perspective we’ve got lots of new toys to start building with. Looking forward to it!

NimbleKit – HTML & JavaScript iPhone Apps

Sunday, May 31st, 2009

The question has been coming up a lot lately: how can we build iPhone apps using the familiar medium of HTML and JavaScript? Already there are several options available to us, including the popular open source PhoneGap framework from Nitobi. Alexander Voloshyn wanted to take a stab at solving the problem too – the result of which was NimbleKit. His approach was more of a purpose-built framework specifically for iPhone than a general-purpose solution that could be applied to multiple devices. He’s also packaged his solution up with short-turnaround support all for just $99. I asked him some questions about NimbleKit by email. Here is our conversation:

Q. Tell me about the NimbleKit project. What problem are you solving?

There many people who have great ideas of iPhone applications but simply don’t know Objective-C, with NimbleKit it is easy to create own applications using just javascript and HTML. For those who know Objective-C NimbleKit is a huge time saver.

Q. What types of apps are best suited? Could you write a game? What are the limitations?

With NimbleKit it is possible to write wide range of applications, we can display text or image information, play audio, navigate between pages, read files and request any data from internet, interface elements have javascript callbacks to provide interactivity of interface, so to answer your question practically any application can be written using NimbleKit.
Unfortunately applications which use complicated drawing and OpenGL ES are not supported which means no complicated games, but of course you can do simple games on javascript using AJAX.

Q. What level of Objective-C knowledge is required to build a NimbleKit app?

None. However in version 2.0 we plan to give possibility to mix javascript and Objective-C, this way actually practically anything will be possible including OpenGL ES and WebKit mix.

Q. Are there any released apps or projects in the works now that use the framework?

NimbleKit is still very new so nothing yet in app store released, however we understand it is important for our customers to know they can release their apps without any problem, so we develop couple apps to release soon.

Q. Do you anticipate any problems having apps accepted into the App store?

Should not be, everything NimbleKit uses is allowed by Apple. However NimbleKit based on HTML and user may expect to load all app’s content from internet, but doing this will cause problems, most likely Apple won’t approve it because once it’s approved app’s content may change to adult or similar.

Q. Do you have any plans to port the library to non-iPhone platforms?

The library takes all advantages of it’s platform and should not exclude or complicate some features because it is required to be compatible. If we decide to make SDK for another platform we will make it from scratch using all it’s capabilities.

Q. How do you compare your framework to ones such as PhoneGap, Nemo, or Rhomobile?

Compare to similar frameworks NimbleKit has huge advantage in features, documentation, support and ease of use, only NimbleKit can provide you with working application in 3 clicks.

Also there is a big difference in architecture, NimbleKit made the way it can be extended to implement practically any feature, which is not possible with other frameworks.

Q. Right now you’re selling licenses for $99. What level of support do users get for that? Any other perks?

All general questions answered usually within 1 hour. For registered users we provide code level support. Also mailing list available and forum (launches 29 of May). All users can request any features, however registered users get their requests fulfilled first including personal pre-released patches available next day after problem appeared.

Free 30-day trials are available from the NimbleKit website.

EasyGlyph Updated – Kerning Fixed + Dropshadows

Friday, May 29th, 2009

About a week ago I released a font system for the iPhone called EasyGlyph. I looked into switching over to a native true-type-font loader but came back to this because it still seems like the cleanest solution. I noticed there were some issues with the kerning so I fixed that, and added support for drop shadows and glow:

screen-capture-11

Drop shadows really help the fonts stand out. Give it a try! If anybody wants to help convert this to a library that supports Android or other platforms, I’m happy to assist. Just email me: alexei.white@gmail.com if it’s your intention to do this.

screen-capture-21


Will Apple Permit JavaScript-based Apps?

Monday, May 25th, 2009

There seems to be a real movement afoot to provide means for developers to write native or near-native phone applications in ECMAScript. PhoneGap is doing it, Rhomobile is doing it, Palm Pre is doing it, and now Haxe is doing it.

HaXe has always been an interesting project. It’s basically a JavaScript compiler with targets for Flash 6-10, PHP, C++, Java, etc. Now you can write HaXe projects for the iPhone. Pretty cool stuff. This is certainly along the lines of PhoneGap in that it helps democratize the platform – however – I suspect it probably violates the iPhone terms of use in that it basically becomes an interpreter:

Usage of such non-public API, as outlined in the iPhone SDK Agreement section 3.3.2 is prohibited:

"An Application may not itself install or launch other executable code by any means, including without limitation through use of a plug-in architecture, calling other frameworks, other APIs or otherwise. No interpreted code may be downloaded and used in an Application except for code that is interpreted and run by Apple’s Published APIs and built-in interpreter(s)."

This seems to be sortof the same problem suffered by apps written using the popular phone framework PhoneGap (http://ajaxian.com/archives/someone-at-apple-please-review-stance-on-phonegap). While I see the need to control how code is executed when running outside the normal security sandbox of a browser, HaXe seems fairly tame because as far as I can tell, the application code is not being altered after the program is compiled (could it??). In any case, you’re still compelled to operate within the same runtime sandbox as a normal Objective-C based application.

In any case, if Apple is going to continue to crack down on frameworks like this, I hope they pick on the way the wind is blowing and provide something to the community that lets people marry the familiar world of ECMAScript, HTML, and/or CSS with the powerful features of the iPhone.

EasyGlyph – Another iPhone Font System

Thursday, May 21st, 2009

See the end of this article for the download link..

Update: 1.2 Is now available. It contains important bug fixes and support for drop shadows.

So Apple provides a number of fonts for use in your iPhone games and apps including:

  • American Typewriter
  • American Typewriter Condensed
  • Arial
  • Arial Rounded MT Bold
  • Courier New
  • Georgia
  • Helvetica
  • Marker Felt
  • Times New Roman
  • Trebuchet MS
  • Verdana
  • Zapfino

These are fine, but what if you want to use your own fonts in a game or application? There are a couple ways to do this (http://stackoverflow.com/questions/360751/can-i-embed-a-custom-font-in-an-iphone-application) – but I wasn’t entirely satisfied with these. To do this is somewhat tricky because you have to store the kerning (spacing) information as well as the bitmap for the font, and provide tools for slicing up sprite bitmaps directly on the iPhone. I took a day or so and wrote a tool to rip the windows font of your choice, and create a UIImage, which can then be converted easily to an OpenGL texture if needed. I call it EasyGlyph and the tool is free to use but devoid of any warranties.

First of all, there’s a Windows application that stitches together the font “sheet” image and calculates all the letter sizes and kerning. You start by generating a 32-bit (with Alpha) PNG graphic of the font using a font face, size, and color. You can of course size any font to whatever size you want once its on your iPhone, but depending on the situation you may want your font to have more or less bitmap detail (remember we’re converting it to a bitmap from a vector drawing). Here’s a screenshot of the tool:

EasyGlyph

Here’s what some Windows fonts look like rendered on the iPhone:

screen-capture-4

Mind the spaceships. They’re part of a game, and aren’t relevant to this article. Because of the kerning code, it can also handle complex overlapping fonts like this:

screen-capture-5

When you save a font to disk, you’ll get two files: a PNG file containing the bitmaps and a C document containing the class constructor along with all the coordinate and kerning information for the font:

myFont = [[EasyGlyph alloc] init];
[myFont initFont:@"chicdecay.png":@"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 1234567890.,-=+:;<>?!'\"[]@#$%^&*()/\\":@"0,0,69,115.937,37;79.783,0,71,115.937,37;157.421,0,71,115.937,36;236.569,0,67,115.937,37;318.129,0,62,115.937,37; ETC...

You’ll need this along with two classes: “EasyGlyph” and “CustomFontChar” which are included. To generate a bitmap of some text that uses the font, use the instance method writeTextToTexture, which returns a UIImage instance:

[myFont writeTextToTexture:@"Hello World!"]

To convert this to a Texture2D, for use in OpenGL applications, you can do something like this:

textTexture = [[[Texture2D alloc] initWithImage:[myFont writeTextToTexture:@"Hello World!"]] retain];

.. and you’re off to the races.

I’m looking for feedback, improvements, insults – whatever you got basically. Once again this is free to use – I only ask you provide some feedback if you got some use out of it. Enjoy!


iPhone Development Frustration

Tuesday, May 12th, 2009

One of the most frustrating behaviors of the entire Iphone development stack is the constant iPhone brickings I have to endure (see image). Every week or so I’m forced to restore the phone from an image because XCode simply says “Could not support development.”. Oh that’s nice. THANKS you jerk. I get like 4 hours a week to work on these projects and I just long spending 1 of them restoring my phone.

Anybody else seeing this message? Any idea why it happens?

A Tool for Creating OpenGL Animation Textures

Tuesday, May 12th, 2009

Updated Sept 28, 2009: You can now hard-code the number of columns. Also included the full source code.
Updated: I fixed a bug to do with image sizing. The new download is at the end of this post.

I’m in the midst of writing my first iPhone game. I had a need to create an animation from a series of frames I produced in 3DS Max and play them back in the game. I googled the web for the best way to do this and it seems for short animations (less than 50 frames or so) like explosions and rotating asteroids the best technique for OpenGL is to stick them all together on the same texture and just change the displayed coordinates on the polygon I was using. For example:

I began by doing this myself, manually in Photoshop. What a time waster! Every time I wanted to update an animation or tweak it, it represented up to an hour of work just to do the work of resizing and stitching the images together on a grid. I then had the bright idea of automating the process. I wrote a tool in .NET that does exactly that, while preserving the alpha channel of PNG images. It sorts (by filename), resizes, stitches, and outputs the result to a neatly sized PNG graphic that can then be converted to an OpenGL texture. Remember that if you use this tool, the maximum texture size is 1024×1024 so you have to limit your animations to something that will fit in that grid.

I first tried it with an asteroid animation and it worked nicely. I’ve included the asteroid frames in the download for you to use or as an example. I also did it with an animation I made in ParticleIllusion for an explosion:

screen-capture

Now, on the Objective-C side of things, you need to write a class that can take these stitched assets and animate over each frame. I’ve whipped something up using the Texture2D classes provided by Apple (which I’ve augmented somewhat). Three methods are provided:


-(void)setupAnim:(int)pxWidth:(int)pxHeight:(int)frameWdth:(int)frameHt:(int)frmCnt

This takes the pixel width and height of the entire image, as well as the pixel width and height of each frame, and finally the number of frames.


-(void)incFrame

Initially the currentFrame value is set to 0 (the top left frame). You can manually set this property, or use this function incFrame() to bump it up one. When the end is reached, it will loop to the beginning.


-(void)drawFrame:(Texture2D*)animTexture:(float)x:(float)y:(float)width:(float)height:(float)rotation

This will draw the frame using the special Texture2D class I provided with an x,y, width, height, and rotation (in degrees).

If you have suggestions for a better way to do what I’m trying to do – please let me know! This utility is free to download if you find it useful, however.

Below you can see the asteroid in action!

screen-capture1


Book Review: The Busy Coder’s Guide to Android Development

Wednesday, April 22nd, 2009

I’ll Only write a review about something I like.  That’s good news for Mark Murphy and his book:  The Busy Coder’s Guide to Android Development.  I’ve found this book invaluable in writing my first Android application since I’m not yet familiar with the sometimes perplexing details of the android API.

Busy Coders Guide

Busy Coder's Guide

The book is available in print or through Murphy’s website:  http://commonsware.com/ .   I Strongly recommend the latter for a few reasons.  Firstly Android is a [rapidly] moving target.  The website purchase allows you to download updates for a year and updates do seem to appear from time to time.  Secondly you also get access to the unfinished advanced book.  While that book is unfinished it just so happened to contain a completed chapter explaining exactly what I wanted to do.  Once your subscription runs out you still get to keep the books in pdf form.

Rather than go through an exhaustive list of the contents I’ll tell you what I’ve found useful so far.

The book has LOTS of details on android widgets and how to describe them in your layout xml’s and access them in your code.  It details some of the fancier things you can do such as dynamic list content (albeit different than my earlier posting) and an options menu api.

The book has some chapters on thread handling and application lifecycle.  I had previously spent weeks combing these details out of various message boards and mailing lists as well as pouring over the then-unclear api documentation.  These chapters would have been a big time-saver for me.

Probably the biggest deal for me is addressed in this book and continued in the advanced book:  Background Processes.  There are all sorts of different ways to set up background processes in android and all sorts of different ways to communicate them.  If you’re struggling with untangling the mystery of persistant programs in android this will be $35 well spent.

There are a couple of things that annoyed me a little about the books.  Code blocks are split up into snippet-description-snippet-description sequences so sometimes you have to put the pieces together a little.  He doesn’t always specify where the code would belong in your directory structure (please fix this one thing if you ever read this Mark).  The unorthodox naming of chapters might make it a little tough to quickly find what you’re looking for but they add a lot of character so I’m actually fine with it.  Just be prepared.

All in all the Busy Coder’s Guides are great resources and well worth the money.  I have it open on my other screen *right* now as I write this and will be using it to help put a few finishing touches on my program this afternoon :-)

- Tyson

Cocoa – NSThread And Memory Management

Thursday, April 16th, 2009

As a C/C++ developer one tends to be acutely aware of the implications of dynamically allocating memory from the heap.  In the past couple of months I had decided to expand my horizons and engage in developing some applications for Mac OS X and iPhone using the Cocoa libraries and as such, Objective-C as my implementation language.

Everything was moving quite smoothly in my single threaded application.  At a certain point it became apparent that it was time to decouple the GUI and the data collection.  I had decided to implement the data collection in a thread.  A NSThread specifically.

As I began to implement the main function of my thread I began to notice some horrible messages showing up in the XCode console:

2009-04-15 20:51:35.030 HostWatch[18804:440b] *** _NSAutoreleaseNoPool(): Object 0x20f240 of class NSCFString autoreleased with no pool in place - just leaking

Stack: (0x9711373f 0x9701fe32 0x139e7 0x1441a 0x970267ed 0x97026394 0x962b1095 0x962b0f52)

2009-04-15 20:51:35.033 HostWatch[18804:440b] *** _NSAutoreleaseNoPool(): Object 0x276530 of class NSCFData autoreleased with no pool in place - just leaking

Stack: (0x9711373f 0x9701fe32 0x97034505 0x97086a48 0x1443c 0x970267ed 0x97026394 0x962b1095 0x962b0f52)

2009-04-15 20:51:35.033 HostWatch[18804:440b] *** _NSAutoreleaseNoPool(): Object 0x276480 of class NSCFData autoreleased with no pool in place - just leaking

Stack: (0x9711373f 0x9701fe32 0x97034505 0x97086a48 0x14463 0x970267ed 0x97026394 0x962b1095 0x962b0f52)

Just leaking!!  Oh my!  My spider senses were tingling.  My heap sensitive programming sensibility in shambles!  Something had to be done.  No one wants a program that should theoretically be running for a long time (or any amount of time) haphazardly shedding dynamically allocated memory.

The solution turned out to be quite simple.  The main function of a NSThread should always be wrapped in an autorelease pool.  So, the solution in code might look similar to this:

- (void)threadMainFunc:(void *)data
{
   NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init];
   ...

   ...
   [autoreleasepool release];
}

Sweet relief.  All of the nasty message pointing to blatant leaking of memory had disappeared. The details of Cocoa’s requirements with respect to autorelease pools and threads can be found here:

Autorelease Pools

and more specifically on the topic of threads:

Autorelease Pools and Threads

I hope that this has been helpful for anyone who has had this sort of issue show up in their newly NSThread-ed code.  My intent is to continue posting as I encounter and solve problems in my current Cocoa development projects.

Free Graphical Layout Editor for Android

Wednesday, April 15th, 2009

Quick one for you Android coders out there.

Have you ever had trouble getting a layout to look just right for one of your activities? Have you had trouble coming even close? Me to. Check out this tool. It’s a gui layout editor that’s helped me lots of times come up with the right xml for my layouts or tweak what I had come up with already. It’s an applet that will run in your browser to:

http://www.droiddraw.org/

-Tyson



© All rights reserved.