All atomic-powered posts filed in “Mobile”:



MPMoviePlayerViewController: Check yourself before you wreck yourself

iOS pop quiz:

~90% of the time, this code will show a video.
~10% of the time, this code will show a screen with multimedia controls but no video.
If the user rotates their device, the video will then show correctly, even if the user rotates it back.

Why? And how do we fix it?

No idea yet. Let’s check the loadState, just for fun.

When it works, the loadState is 3.
When it fails, the loadState is 0.
Interesting.

For reference, this is what 3 and 0 map to:

MPMovieLoadStateUnknown

Cryptic. Let’s check the docs and see what it means.

Image and video hosting by TinyPic

MPMovieLoadStateUnknown

The load state is not known at this time.
Available in iOS 3.2 and later.
Declared in MPMoviePlayerController.h.

Okay. Since the documentation is “concise” at best, let’s just assume that the video isn’t ready yet, for whatever reason. And, once we’ve forced it out into the limelight, it just stands there trembling with stage fright no matter how long we wait—unless we rotate the device, which is the iOS equivalent of yelling “Snap out of it!” and delivering a firm slap to the face.

So what’s the solution? Simply check yourself, lest you wreck yourself.

It ain’t pretty, but it fixes this subtle bug that probably exists in most apps that play movies.

Native App Vs. Mobile Friendly Web Application

There are two main ways to create mobile applications. The following post lays out advantages and disadvantages of both approaches.

Native Apps – applications that are installed directly on smart phone devices (iPhone, Android, Blackberry, etc.).

Advantages
  1. Cool Factor – “There’s an app for that.” Being in the Apple App Store or Google Android App Market is great marketing for an organization.
  2. Application Icon – When an app is installed its icon is placed onto the user’s smart phone desktop.
  3. Experience – Native apps are generally faster and more fun to use.
  4. Hardware Access – Native apps can easily take advantage of a smart phone’s GPS or camera.
  5. Offline Mode – App features can be developed that do not require an internet connection.
Disadvantages
  1. Many Platforms – Each application is unique to its platform. For example, an iPhone app will only work on an iPhone. If you want it to also work on a Blackberry, you will need to create another application tailored to Blackberry. New frameworks are being developed to help ease this pain.
  2. Many Versions – When a new version of an existing native app is released, the users of the native app will need to download and install the update. People are not forced to update; therefore there will be multiple versions of the application in production.

Mobile Friendly Web Application – web application that is easily viewable and usable on a smart phone.

Advantages:
  1. Reaches everyone – Anyone that has an internet enabled phone can view the application.
  2. Web application already exists – If a web application already exists it can be updated to accommodate mobile phones.
  3. One Version – Updating the website updates all the application users.
Disadvantages:
  1. Not as cool – There is no app store or app icon. You need to access that application through your mobile browser.
  2. Must be online – The application only works when you have internet connectivity.
  3. Limited hardware – Although it is technically possible to access some smart phone hardware from a website, it is not as seamless.
  4. Optimized look and feel – Each smart phone has its own look and feel and screen dimensions. Optimizing the web experience for specific smart phones requires implementing various mobile stylesheets.

The correct approach in any given situation depends upon the experience you are trying to achieve. It is important to note that this decision is not mutually exclusive. In some cases it makes sense to do both.

Migrating to Closures in Objective C

Apple introduced closure support with the release of Snow Leopard. Plausible Labs has since created a framework and a drop-in runtime that provides closure support for both MacOS X 10.5 and the iPhone SDK. Closure support is a fundamental and important change to the Objective-C language. Functions are now first-class citizens in the runtime environment; they can be saved, copied, and passed around just like any other object.

That being said, much of the existing API in both MacOS X and the iPhone SDK rely on callbacks, selectors, and delegate patterns to cope with lack of first-class functions. But don’t let that stop you from using closures. It is relatively easy to create small intermediary wrappers that bridge the gap between callbacks and closures.

Read the rest of this entry

iPhone, meet ArtPrize

Pomegranate Studios, the masterminds behind the international ArtPrize contest, worked closely with Atomic Object to develop an application to let voters use their iPhone to participate in the event.

ArtPrize is a radically open competition where the winner is decided by public voting. Starting on September 23rd, the contest will run for two weeks with the final winner announced on October 8th.



The ArtPrize app allows users to locate artists' installations throughout downtown Grand Rapids, utilizing Google Maps on the iPhone. Once you've registered to vote, you can easily vote for your favorite artists using the app. The app also encourages users to engage with others via Facebook and Twitter, allowing audiences to express their opinions and observations in real-time. Mlive, a statewide Michigan news site, praised the ArtPrize app for its usefulness--particularly for the ability to preview artists' works and locate venues.

Atomic Object is pleased to be a part of something so creative, innovative and beneficial for the community of Grand Rapids.

The ArtPrize app is available the App Store now. Click the button below to see it in iTunes or just search for "artprize" on your iPhone.

"A New Earth" iPhone app

Our first publicly available iPhone application is now available in the iTunes Store. It's an application for the book A New Earth by Eckhart Tolle. Working with our partners at Six Voices, we developed a framework called TapStack which provides a card-based system for viewing and navigating content on the iPhone. The application was designed to provide a very realistic sensation of working with a deck of cards.

You can check it out on iTunes.

There were some interesting experiences with iPhone development that we'll cover in future blog post. One useful tip to know is that the UIImage class will try to manage its own memory if you construct it using the initWithContentsOfFile: method. This means it will unload and reload the image from the file as needed, which can kill performance if you're dealing with a lot of offscreen images that need to be shown on screen quickly. Using initWithData: using an NSData will let you manage the memory yourself.

iPhone Development Experience

I had the opportunity to attend Apple's World Wide Developer Conference this past June. I attended the conference to learn about and gain experience in iPhone development. Most of my time was spent in the iPhone Lab and iPhone development presentations and sessions. I thought most the presentations were informative and well presented and I came away with a lot.

My only complaint is that Apple would not talk about or even acknowledge the more complex areas of sample code in their presentations. It was obvious Apple was focusing on making iPhone development look very easy through and through. And compared to other mobile platforms it is easier. However I wish they had spent some time going into the more complex, non-apple abstracted code that actually takes some time and thought.

The development experience is a good one. The language (Objective C), iPhone SDK and the development tools are well done. Objective C is a powerful object oriented language and the iPhone SDK is well abstracted and easy to use. If you need access to the more low-level API's they are readily available. Interface Builder is spectacular and it puts other interface/view building applications to shame. Xcode is still way behind other IDEs but it is very usable nonetheless. Their performance and debugging tools are excellent. Even when your code is well formed and well tested you have the potential to have memory leaks, and their memory leak detection tool is great for that kind of problem.

From a professional development standpoint the platform is ready to go. A developer can test drive their code using OCMock and OCUnit. If you prefer a different testing platform I recommend looking into rbiphonetest.

I was able to successfully create an iPhone application using Atomic Object's Presenter First style of development. However, bootstrapping the application becomes problematic when the application uses a great deal of composition. It would be nice if a dependency injection framework existed and was available for iPhone development. However, it is possible to use Interface Builder to instantiate all of the singletons in the system and inject them, which could be an acceptable alternative.