Archive for the ‘coding’ Category

Ad Hoc Test Devices limited to 100. And I mean it!

November 6, 2009

Had a rude awakening a couple of days ago that the 100 devices available in the iPhone Developer Program for Development and Ad Hoc testing is a high-water-mark limit. Once a slot is allocated to a UDID, cannot be reassigned to another device.  You can remove it, but it does not release the slot for a different device.  The remove operation is more like a disable operation meant for preventing access to your test application, e.g. if a beta user started abusing your system in some way.

What does this mean to you, the developer?

You will definitely used up one UDID for your development iPhone.  If you are running a beta test of your application on, say, 50 beta test users.  You collected the 50 UDIDs fromt them.  Uploaded them to your Developer Portal and generated the necessary mobile provisioning files.  You are done with your beta test.  At this point, you have 51 UDIDs in use.

You want to do a second beta test (may be for a different app, or another version of the same app) with a different set of 50 beta test uesrs.  Whoops…too many.  So I deleted the 50 UDIDs from the first beta test and want to add the 50 new beta test users.  Whoops 2!  I cannot do that.  I can only add 49 of them.

Here’s Apple Math:

  • Start: 100 slots
  • Subtract 1 for my Development iPhone. You have 99 left.
  • Subtract 50 for the first set of beta testers. You have 49 left.
  • Add ZERO for deleting 50 users of the first beta test. You still have 49 left.
  • Subtract 49 for the second set of beta testers. You have 0 left.  The 50th beta tester cannot be added.

At this point, you are “done”.  You can no longer add any more devices to this account.  Suppose you bought a second iPhone for testing.  Well, you can’t add it and use it for development testing cause you are out of slots.

The “remove” command makes you think that you can free up a slot.  No it doesn’t.  And once a device is deleted, it cannot be undeleted either.  So you are truly and royally hosed at this point.

There’s one solution though.  Time.  You can wait till your one-year iPhone Developer Program is up for renewal.  Once you renew, you can delete all your devices and then you have 100 available slots again.  You can also apply for a second iPhone Developer Program account, wait 2 weeks or so, pay $99, then you have a second set of 100 slots.  But this will be a different account from the first one and you will still need to maintain the first account for publishing your app.  This second account is purely for development only.

I certainly hope Apple will change this policy in the future.

Advertisements

Will Three20 be flagged as “private framework”?

November 3, 2009

Three20I used the open sourced Three20 iPhone UI library for a recent project. It’s a bit heavy duty if you just need one of the nice UI thingies that is in Three20.  In my case, I want to reuse the photo viewer in a client’s project.  I spent almost a whole day trying to understand how Three20 works and how to adapt some part of it, but it is worth it. For example, the photo viewer is designed to take over the entire phone screen.  But our UI design requires that we keep the Navigation Bar on top visible for context.  With the client’s approval, I incorporated a modified Three20 library in the project and delivered the iPhone app prototype within a week.  I came through like a superhero even though I’m just standing on the shoulder of giants.

What’s nagging me in the back of my mind is the possibility that Apple App Review will reject the application because it uses a “private framework.”  I’ve advised my client of that and they are fully aware of the risk.  However, given the way Apple works, the only way to find out is to finish the app and submit it.

Right after submission, I came across some chatter about Apple rejected an app because it uses Three20.  Specifically, it is about a private API called simulateTapAtPoint:. Joe Hewitt was contacted by Apple and Apple explained why.  There is a suggested fix of commenting out some of the offending code with #ifdef DEBUG to make Three20 kosher for Apple App Review.

Some stories have happy endings after all.

iPhone Memory Management Rules-of-Thumb

October 25, 2009

This is a great document from Apple on Objective-C / iPhone memory management and the practical cookbook tips on retain/release.  I suspect that you have to be logged into Apple Developer Network website to read the document. I’ve read it a while ago and re-read it over the weekend.  You should read it from beginning to end a few times 🙂

Here are a few quick rules-of-thumb I use.

  1. If the message that gave you an object does not have “alloc”, “new”, “copy”, “retain”, you don’t have to release the object.  In other words, calls to [NSDictionary dictionaryWithContentsOfURL: …] and [NSString stringWithFormat: …] are cool.  These are convenience functions.
  2. Objects in a collection (i.e. NSDictionary, NSArray, etc.) are managed by the collection.  The implementation of the collection takes care of the retain/release.  When you release the collection itself, the implementation will release the objects in the collection.
  3. Autorelease Pools should be used sparingly – You wouldn’t need to create Autorelease Pools yourself unless you are running things in a thread you spawned.  Refer to the document.  Autorelease Pool is NOT garbage collection, it is an extension to the retain/release reference count memory management system.
  4. UI Objects loaded from NIB files use Assessor methods.  If you declare @property with (nonatomic, retain) for the IBOutlet instance variables and use @synthesize, you do not need to do anything with with retain yourself, but you do have to release them in your dealloc() method.  If you create your own UIView objects from a ViewController, you are responsible for cleaning up after yourself.
  5. Use Assessor Methods in your code.  My rules-of-thumb are:
  • Always use @property / @synthesize
  • Set values to instance variables with self.variable = …
  • Get values to instance variables with just variable. Some may question this specific rule of thumb on the basis of consistency with the rule above. I can be sway the other way, but since we use instance variables a lot more than setting instance variables, I use this rule to make my code more readable.  See following rule.
  • Be consistent.  Alternatively, although a bit more verbose, set values with [self setVariable: …] and get values with self.variable.

In iPhone OS 3.1.2 Upgrade Hell right now

October 14, 2009

I accidentally upgraded the iPod touch I use for development to iPhone OS 3.1.2.  Doh!

Now, I cannot use it with my current installation of Xcode 3.1.3 and iPhone SDK 3.0.x to develop/test with this iPod touch.  And I cannot downgrade back to 3.0.x either.  Bummer.

So I started downloading Xcode 3.1.4 with SDK 3.1.2 from developer.apple.com and hope to do a quickie upgrade and get myself back to be productive again.  Not so fast.  The download is 2.7GB and took 1.5 hours. Then when I tried to install the Xcode upgrade, it failed.  It reports some type of checksum error.  See this:

InstallFailed

I tried this 3 times and it failed in different places.  I used md5 to check the checksum.  The three different .dmg files came back with different checksums.   Since I don’t know what the checksum is supposed to be, all I know is that the 3 downloaded .dmg files can be all corrupted.  And I have no way of figuring out which one is the good one, or if I even have a good one at all.

I did google around to see if anyone has the same problem so I can point fingers back at Apple.  No such luck.  Looks like I’m the only person seeing this problem.  Good that I have been diligently backing up my MacBook with Time Machine.  Since the botched installs of Xcode 3.1.4 renders my Xcode installation unusable, I used Time Machine to rewind time and get a working Xcode again.

Lessons learned:

  1. Back up your development Mac with Time Machine before you upgrade Xcode.
  2. iPhone / iPod touch OS upgrades are one-way street.  Don’t believe anything else.  Make sure that you have more than one device on hand for development and testing.

Epilog: I gave up on Xcode  3.1.2 on Leopoard!  I went out to Apple Store, bought a copy of Snow Leopard, backed up my MacBook with Time Machine (Do this!  Trust me!  You won’t regret it as Snow Leopard installation will likely require that you reformat/re-partition your hard disk), upgraded to Snow Leopard, upgraded Xcode to 3.2.1.

iPhone Dev Camp 3 Weekend Recap

August 3, 2009

It was a fun weekend at iPhone Dev camp 3 at Y! Sunnyvale HQ.

iPhone Dev Camp sign

iPhone Dev Camp sign

Day 1 – Friday 7/31/09

Friday night was a nice relaxing evening with just one keynote by Chi-Hua Chien from KPCB iFund.  See my previous post for details.  His slides are posted online here. The rest of the evening was roaming around and network. Met many nice people. Hovered around Christopher Allen to see what Hackathon projects are available.  A few that interested me:

  • GetAround – Charles Du and his team of green-shirted friends looking for “rockstar programmers” with MapKit experience.
  • Chief Medical Officer – Bess Ho and Jen McCabe assembling a team to make Google Health more useful.
  • Foodspotting – Alexa & Seth wants to build a visual, dish-centric, social app for foodies.
BT spinning, Geeks Dancing, iPhones taking pictures

BT spinning, Geeks Dancing, iPhones taking pictures

BT was playing trance electronic music outside.  I was out a bit watching geeks dancing. But there are just too many flying buggers.  When they start to swim in my beer, it’s time to head back inside.

Hot dogs were served for dinner, with beer on tap (after keynote). I overheard some people who mumbled “What? Hot dogs for dinner? How lame?” I did not butt in, but at $50 for a weekend of food and fun, what do you expect? Beluga caviar and Dom Pérignon?

Day 2 – Saturday 8/1/09

Arrived bright and early at 9am.  Bagels, pastries, coffee, OJ. Lots of people already.

Slide from Andrew Stone's presentation

Slide from Andrew Stone's presentation

The morning session started late.  Sorted of expected. The Andrew Stone keynote on How  NeXT computer became the iPhone is an excellent talk about the history of NeXTStep.  I was remotely connected to the NeXT through FrameMaker‘s availability on the NeXT cube.

I finally decided to join the Foodspotting Hackathon team and forgo many of the equally interesting sessions.  The team includes Alexa & Seth Andrzejewski, Aaron Bannert, and Warren Stringer. Around 2pm, we started really talking about limiting the capabilites so we can create something that demonstrates the concept and vision within 24 hours.  Alexa got many screen mockups already. We were able to define what functionalities can be done and what the screens should be by around 4pm.

I started putting the Xcode project together as the framework and CVS it.  Aaron & Warren worked on the data model.  Alexa & Seth provided the missing graphics and whatever we need. Magic Seth walked over and helped me with the iPhone camera integration code so the Foodspotting app can launch the camera to snag photos of food.

Indian food for dinner!

Indian food for dinner!

Over yummy Indian dinner, we continue to hack away with more code and before the 10pm shutdown time, we have a version that includes taking photos, showing the MapKit view with current location, and the beginnings of the streaming photos view and loaded it on my iPod touch and Alexa’s iPhone.  We were kicked out of Y! building 10pm-ish.  I braved the crazy flying buggers in the parking lot and headed home.  A bit more hacking at home before heading to bed.

A side note: Greystripe got some interesting stuff left in the Men’s room.  I should have taken a picture. It’s in a small plastic pouch, comes in various colors, and with the tagline “Because app developers deserve protection too!” Go figure 🙂

Day 3 – Sunday 8/2/09

Bagels, Muffins, Pastries, ...

Bagels, Muffins, Pastries, ...

Back to Y! campus by 9am.  Staked out at a table near the food and coffee and continued hacking away.  Warren started integrating his MapKit Annotations and Core Data models into the UI I built (and fixing the bugs I introduced last night, thanks, man!).  Got the streaming photos working.  Got the photos zoom UI working. We kept the UI very simple so we can get the application working quickly.  And instead of pulling data off the network, all the map pin drop annotations are bundled into the application.  Alexa and Seth worked on the presentation (which was so good that it wow’ed the crowd, but none of us have seen until demo time) while constructing the data set we use to seed the application with interesting pictures and geo-locations.

Sunday lunch: tasty tacos

Sunday lunch: tasty tacos

Aaron was debugging with Warren.  Seth called for help, at Warren’s direction, from the mic on stage for various Core Data and Map Kit issues several times.  Helpful helpers showed up faster than you can say “911”. Pretty much all of us worked on the application non-stop and skipping lunch.  Seth brought us tasty tacos so none of us fainted at the keyboard.

iPhone apps is the new web site

Phone App is the new Website

We signed up online for the demo before the 1pm deadline. Completed our demo-able application on the iPhone. Completed our presentation slides. Then we relaxed and watched other Hackathon Demo presenters.

Foodspotter Hackathon Team Photo

Foodspotting Hackathon Team Photo

Then it’s our turn.  We were slightly delayed after hitting into some snag with hooking up Alexa’s MacBook Pro to the projector.  But we finally got started with the demo.  (Lesson learned: Let Mac OS X take care of video switching.  Instead of manually setting the MacBook to 1024×768 to match the projector, just leave it alone, plug the video cable in, and Mac OS X will takes care of it. If not, you lose.) The slides were great.  The demo worked perfectly.  Crowd cheered. We knew there are bugs, but we were careful enough to only do things that are “safe”.  It’s my “machéte a path through the jungle” demo philosophy at work.

Out of the corner of my eyes, I saw Robert Scoble sneaked up towards the stage and took a picture of us.  I asked him afterward what he thinks of Foodspotting application. He said he likes it!

Then comes the nail-biting time of waiting for the judging.  We just hung around talking to people and networking.  When the winners announcement comes to Best Social Applications–It’s Foodspotting!  We jumped up and down and went up to claim our loot which includes: 8GB iPod touch, Elgato H.264 HD encoder, and MobileMe family pack.  We also picked up several other small prizes with our blue “helpful” tickets. Here’s the list of all the iPDC3 Hackathon winners.

The Foodspotting team went out to Shanghai Flavor in Sunnyvale for our celebration dinner and get to know our weekend Hackathon teammates a bit more.

At iPhone Dev Camp 3 this weekend

July 31, 2009

About to head towards Sunnyvale Y! campus for iPhone Dev Camp 3 for the weekend.  Follow the events with #ipdc3 tag on twitter.  High hopes to learn something and meet lots of new friends.

How to Use iPhone 3.0 Features and Still Run on 2.2

July 2, 2009

iPhone SDK 3.0 has a lot of nifty new features.  One feature I want to use is to send email without exiting my application.  In the past, I have to use UIApplication openURL: to launch the Mail application.  But once I do that, the user is gone, gone, gone.

In SDK 3.0, there is a MFMailComposeViewController class that allows me to bring up a Mail Composer view.  When the user is done with the email and tap Send, user is back in my application.  Can it be cooler than that?

Yes, of course.  Using the MFMailComposeViewController class, I can also preload the body with an attachment.  So, if my application generates a graphical chart, a CSV file, a sound file, etc., I can attach it to the email that is being sent.

The MailComposer sample application (you may need to be logged into Apple’s Developer Connection to access this link) goes into the nitty gritty details on how to use this new class.  Definitely dig into the sample code.

My first question was does that mean that my application is now limited to iPhone OS 3.0 users?  I don’t want to do that as it excludes a large segment of the population who did not bother to upgrade (even though the upgrade is free on the iPhone).  Here’s the cool part.  You don’t have to exclude the pre-3.0 users.  The MailComposer sample application goes into the details of how to do that.

  1. You build the application with SDK 3.0.
  2. You target to iPhone OS 2.2.1 (or whatever version you want).
  3. You write your code to check for existence of certain 3.0 framework before using them, and provide a graceful degradation path for pre-3.0 users.
  4. In setting up the Frameworks for your build target, you set the role of the 3.0 framework used in your application to weak such that application will launch even if some of the frameworks are missing.

Step 4 above is the important part.  If you don’t do that, your application will fail to launch on pre-3.0 devices.  The following is the screen capture for where to set a framework’s role to weak.

Xcode example of where to set a Framework to Weak

Xcode example of where to set a Framework to Weak

As for testing, if you have the luxury of a rackful of devices running different OSes, by all means test on all of them.  The other option is to test on pre-3.0 OSes using the iPhone Simulator.  The way to do that is first build and test by setting Xcode to Simulator 3.0 setting.  This leaves a 3.0 version on your iPhone Simulator. Then from the iPhone Simulator men, choose Hardware > Version and select 2.2.1.  Then launch your 3.0 application in a 2.2.1 environment and test away.

Working with Audio in iPhone Applications

June 9, 2009

iPhone OS SDK’s AVAudioPlayer class supports many different audio file formats:

  • AAC
  • HE-AAC
  • AMR
  • ALAC
  • iLBC
  • IMA4
  • linear PCM
  • µ-law and a-law
  • MP3

Different formats consumes CPU resources differently.  Specifically, AAC, MP3 , and ALAC (Apple Lossless) uses hardware-based decoding and the device can play only a single instance of one of these formats at a time through hardware.

Then there’s the file size issue.  Compressed formats such as AAC and MP3 can make your application a lot smaller.  For example, 64kbps MP3 can pack one minute of audio in 100KB.  Using an uncompressed format such as AIFF or WAV can be as large as 1MB or more per minute of audio.

Then, there’s the complexity of audio looping.  AVAudioPlayer class supports looping during playback.  With compressed formats, looping can get tricky.  Unless the MP3 file was created specifically for precise looping, you are better off using an uncompressed format such as AIFF or WAV.

With proper manipulation, you can still control the size of an AIFF file by adjusting the data format and sampling rate.  The application afconvert on Mac OS X can do that very nicely.  I find the combination of AIFF with I8 and 22,050 hz sampling rate gives me reasonable audio in AIFF format:

    afconvert -f AIFF -d I8@22050 input.aif output.aif

This generally results in an AIFF file that is about 25% the size of the original since most AIFF files uses 16-bit and sampled at 44.1 kHz.

iPhone SDK 3.0 Beta 5 available

May 7, 2009

I’ve been holding off upgrading my development environment from SDK 2.2.1 to SDK 3.0 until I get to a “convenient” stage of my development cycle.  Today, I received a email from Apple Developer Program that all new app submissions to App Store will now be tested on SDK 3.0.  If it does not work on 3.0, it will not be accepted.  Oh well, I guess “convenience” has been defined.

Stack Overflow – My new favorite web site for programming answers

April 23, 2009

When I have a programming question, I usually google a few keywords and can usually find the results.  Google results tends to point to many discussion forums sometimes with unanswered questions or to “official” documentation from say Apple or MySQL.  In many cases, I have to google  for the answer because the official documentation is of little or no help.

Recently, I’ve found that the web site that gives me the best result tend to be Stack Overflow.

“Stack Overflow is a collaboratively edited question and answer site for programmers — regardless of platform or language. It’s 100% free, no registration required.”