iOS ALAsset image metadata

Posted: July 10, 2011 by Ash Mishra in Programming

iOS provides a built-in Assets Library, which stores media that you have sycned with iTunes, or stored in your Camera roll. These are usually photos or videos.

The main iOS classes for working with media Assets are the following:

  1. ALAssetsLibrary – which provides access to Photo Groups by category type. (ALAssetsGroupLibrary, ALAssetsGroupAlbum, ALAssetsGroupEvent, ALAssetsGroupFaces, ALAssetsGroupSavedPhotos, ALAssetsGroupAll)
  2.  After picking an ALAssetsLibrary, you can enumerate through the enclosed ALAssetsGroup objects
  3. An ALAssetsGroup object holds ALAssets, which are a wrapper representing a single image or video.

Other posts cover the details on using enumerators and blocks for getting a set of ALAssets, so I will discuss retrieving metadata.  This can be done in two ways:

  1. Call [asset metadata] which returns a dictionary containing metadata for an asset, including most of its EXIF content. When I tried this call, it did indeed work, but you may have some memory issues to deal with unless you ensure the calls are single-threaded.
  2. Use CGImageSourceCopyPropertiesAtIndex to retrieve individual properties from a CGImageSourceRef; this approach allows you to specify exact properties. See example code after the break below on retrieving a property from an ALAsset using this approach.
My tests for fetching metadata show that while option 2 is more code, it is several magnitudes faster than the much simpler [asset metadata] call in option 1.

As an aside, creating a CGImageSourceRef from an ALAssets is easy when it is a jpeg.  However, if you are dealing with other types of media formats, you will get an error when creating a CGImageSourceRef without a source hint identifying the type of image; this is done by passing in the ALAssetRepresentation UTI.


Two IF statements to Avoid

Posted: September 13, 2010 by Ash Mishra in Design, Programming

After 15 years of writing software, I’ve accumulated several thoughts on software design.

I didn’t go to school primarily for Software engineering, and I haven’t spent as much time reading heavy books on the subject as I would like.  Most of my career comes from hands-on experience, and learning from both successes and past reflection.  Indeed the phrase Design Pattern was a foreign one to me until a decade ago when I started realising some of what I had been practicising had terms coined for them.

Through experience, I’ve gravitated to several favourite patterns and key concepts.  On a new project these are the MVC (Model-View-Controller) pattern, the DRY (don’t repeat yourself) principle, the use of Convention over Configuration, the use of reflection, protocols, state engines, recursion, and remote configuration.

Sounds a little like the kitchen sink – doesn’t it?

But sophisticated maintainable software almost completely relies on design.  While there are many facets to design, one that I focus on heavily on is how reusable code is.

I hesitate to say this can be achieved by reading design pattern books, or the use of technical skills, as several times I have made the mistake of repeating these errors.

Read the rest of this entry »

Review of News Apps and Sites on the iPhone

Posted: December 2, 2009 by Ash Mishra in Design, News
Tags: , , ,

If you’ve been busy playing on your decade old N64 (like I recently have), you might not know that iPhone apps are the new gold rush right now, and it seems like every company wants to get an App on the platform to strengthen their respective brands and grab a piece of the pie.

However, as legions of users can tell you, there’s lots of Apps; but alot of them are subpar and reek of mediocre standards – little or no imagination, and poor implementations. And some of the worst offenders aren’t names you would think of.

Let’s look at a few major News apps on the iPhone: NYTimes, Time Magazine, All Things Digital, The Globe and Mail (Canada), and USA Today. Let’s contrast them with two News sites optimised for mobile Safari: TheStar and CBC.

Read the rest of this entry »

Flash Caching on the iPhone

Posted: November 27, 2009 by Ash Mishra in Programming
Tags: , , ,

A regular pattern every programmer has to deal with sooner or later is fetching data from a network resource, and reusing that content in their application regularly. This could be configuration data, rows from a database, xml or html content.  Much of this fetched content does not change while an application is running for a short time; it may not even change for several days.  [On computers with large and stable pipes to networks, fetching the data from an external source is not necessarily that expensive (but even then it is dependent on the size of the content)]

On mobile devices, like the iPhone, caching can be very beneficial, because fetching data from a networked source is considerablly more expensive than on a desktop computer:  the data transfer rate is slower, leading to slower retrieval of content; network connections can be transient as the user of the mobile device moves in and out of areas of network coverage; and there is usually a cap on mobile plans for bandwidth.

Read the rest of this entry »