So for the past two days I’ve had my iPhone app crashing and vomiting “EXC_BAD_ACCESS” in the console. Generally speaking, this error means you’ve released a reference to some object you still need and some other object tried to send a message to said object afterward. It turns out that it was entirely my fault and (GASP) paying a little more attention to Apple’s reference would saved hours and hours of debugging for me.

NSURLConnection is actually pretty simple to use but here are some tips:

  1. Use the asynchronous mode for any reasonably large file (bigger than a few KB) as people might be on a slow Edge network connection and locking up the view is never a good thing.
  2. Do not send the message “start” to your connection if you use connectionWithRequest or initWithRequest to initialize your connection as you’ll get the nasty “EXC_BAD_ACCESS” error mentioned above. The reason for this is simple:  You’ve scheduled your connection to time out in n seconds, the method that initializes the connection starts fetching data immediately. You then send the message “start,” which spins off the connection trying to fetch data again. This works fine except that the original attempt eventually times out and tries to call back, hosing everything over and crashing your application hard core. Oops. You should only send the message “start” to your connection if you initialize it with initWithRequest:delegate:startImmediately.
  3. When setting up NSURLRequest to pass to NSURLConnection, I highly recommend using NSMutableURLRequest so you can set the User-Agent header.  Some http servers may not return data, even for a simple GET without the User-Agent.  It’s my understanding that User-Agents are optional, but I do not know if said server behavior is nonstandard.

    NSMutableURLRequest *request  = [NSMutableURLRequest requestWithURL:[NSURL URLWithString: @"http://myurl.com"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:15.0];

    //Borrow FF2’s User-Agent

[request setValue: @"Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.16) Gecko/20080702 Firefox/2.0.0.16" forHTTPHeaderField: @"User-Agent"];

I hope this saves someone some time.

so drew and i founded a new startup, return7.  we’re each working on an iphone app, and we’re hoping to submit the apps to apple within the next week or two — stay tuned.

If you can’t seem to select the Distribution Provisioning Profile when you’re trying to sign your iPhone app for distribution on the AppStore, here’s a tip:  Check your Keychain Access application, under “Keys” on the left hand side to make sure you have a public and private key for the certificate you request in step 1 of the process.

If you don’t have these keys, remove your certificate from Keychain and remove your provisioning file (from ~/Library/MobileDevice/Provisioning Profile). Installing the same old certificates over and over will NOT help — you have to remove them all from your system and invalidate the certificate and distribution profile on the Apple Developer Connection page, then start the process over again.  When you generate the initial request and upload the certificate request to Apple’s site, check Keychain Access for the the public/private keys — if they’re there, you’re on the right track.

From there, clean your build and follow the instructions on Apple’s site and you’ll be good to go.  Make sure you close xcode prior to installing the provisioning profile again (I just copied mine to the directory instead of dragging it onto xcode or itunes).

Radio Javan is out on the Appstore! Click here or navigate to the music category to download your free copy.

About a week ago, Hamed Hashemi (of RadioJavan.com, coworker at Appcelerator) asked if I wanted to help write an application to stream RJ to the iPhone.  A week (and many late nights spent learning the iPhone SDK and Objective-C) later, RadioJavan.app is alive and kicking.  Look for it on the AppStore soon.  It’ll run on your iPhone (2g/3g) or iPod Touch w/ 2.0 firmware. Thanks to Hamed for letting me help put this together — it was a lot of fun.  Here are some screens to wet your appetite:

Loading Screen
Main screen
Icon


ban people from using my iPhone SDK to do useful things, presumably so I can do those useful things with less features and sell them for more than the 3rd party would with more features.

Edit: Oh and heaven forbid people have applications that actually run in the background.  That would be the “wrong solution” so instead we’ll wait until september for them to give us a server to push “events” to the phones instead of letting us have the functionality immediately.  Everyone should just forget that practically every other mobile platform out there aside from the ever-crappy PalmOS allows background processes in some form or another without killing battery life.

Edit 2: So it looks like it was a sham (copied from the google maps terms), but the first edit still stands.

So I finally fixed that odd crapping out after 30 seconds of streaming issue — I was corrupting the audio buffer in some odd circumstance.  It turns out that Shoutcast 1.9.9 beta (linux only atm) already has native iPhone/iPod touch support so my proxy guy is pretty much moot.  It was still fun to impl and if anyone’s interested in the source, I’ll put it up for download.  Just shoot an email via my contact form or leave a comment.  Unfortunately, I never did fix the client reconnect/disconnect issue.  As for RJ, they’re going to setup an iPhone specific stream shortly using the Shoutcast stuff (much better than each user having to run some proxy software on their computers and deal w/ port forwarding, etc.

So Hamed and I were talking about streaming RJ to an iPhone when we realized that there wasn’t much out there to do it outside of a php script or two that sort-of worked.  Today I made progress on a POC (.net app) that streams (choppy) audio from a Shoutcast stream to an iPhone for about 30 seconds before crapping out. I’ll try to find some time to fix it up next week and throw it out there. It’ll be a single user single stream sort of thing, for now, since it’s much easier to deal with. I need to get over this whole 30 seconds then croak business, make it so it gracefully recovers from client disconnects, and optimize its performance a bit (choppy audio is useless). Hopefully I can finish it sometime next weekend as I’ll be busy this weekend.

So we managed to sneak one additional feature into the upcoming Appcelerator 2.1 release.  Those of you developing for the iPhone will be pleased to know that we added a new condition - ‘orientationchange’ - so you can handle the origintationchanged event on the iPhone in an on-expression.  How cool is that? Very.  So throw this onto the pile with the new build process, project command line tools, the eclipse plugin/ide (written by Mark Luffel), the developer network (it’s slick — just wait’ll you see it), and a ton of little features and fixes all over the place.  Not to mention improvements to a bunch of the widgets (like the datatable which now supports custom formatter functions, sticky sort, etc.). 

If you need a separate CSS file for your iPhone stuff (sometimes little things just don’t look as good as they can without specific style sheets), you need to put this in your head:

<!–[if !IE]>–>
<link media=”only screen and (max-device-width: 480px)” href=”css/iPhone.css” type=”text/css” rel=”stylesheet” />
<!–<![endif]–>

Then, of course, define your iPhone.css. 

keep looking »