0

Solving Simulator Bootstrap Errors

-

I'm sure every iOS developer has seen the dreaded bootstrap error. "Couldn't register com.yourcompany.yourapp with the bootstrap server. Error: unknown error code. This generally means that another instance of this process was already running or is hung in the debugger." After nearly throwing my Mac out the window for the Nth time today, I finally managed to come up with a simple fix. Run this in the shell:

  1. launchctl list|grep UIKitApplication|awk '{print $3}'|xargs launchctl remove
launchctl list|grep UIKitApplication|awk '{print $3}'|xargs launchctl remove

And your bootstrap errors magically melt away.

This occasionally happens when using Xcode to run iOS apps in the simulator. Although the error really gives no indication of it, it's apparently a hung launchd job that somehow doesn't get cleaned up. The above command lists out all launchd jobs, searches for one with UIKitApplication in the name (which will be the job corresponding to your app that's improperly sticking around), extracts the name, and tells launchd to get rid of that job.

I'm still not sure exactly why this error happens. And, as far as I know, the above can't be used on the actual device, so you still have to reboot those to solve it when it happens there, although that's much less painful than rebooting your development Mac. But the above works just fine as a workaround until Apple can get their act together on this problem. I saved the command into a shell script called unfuckbootstrap that I can use whenever Xcode decides to screw up.

0

Installing 4.3 iPhone Simulator in Xcode 4.2 (iOS5 SDK)

-

After having used all the betas of Xcode 4.2 and the iOS5 SDK I faced several problems when finally I downloaded the official Xcode 4.2 from the App Store. I wanted to anyways get rid of Xcode 3.x, 4.1 and so on (I kept them all installed around my hard drive) so I deleted and installed a fresh copy of Xcode 4.2 (btw I’m very pleased with the progress Apple made on Xcode’s stability and feature list).

However a fresh install of Xcode 4.2 comes with only a 5.0 iPhone and iPad Simulator. Luckily you can now pretty easy install also older version of the SDK. Just follow the easy steps below:

1. Simulator 5.0 only, but how to test whether your app is compatible with iOS 4.3?

2. Aha!, click on “More Simulators…”

3. Click “Install” on the row where it says “iOS 4.3 Simulator”

4. After the 4.3 Simulator is downloaded you’ll most probably see this alert (if you have the Simulator app already running)

5. Immediately after the install is done have a look at the list of available schemes in your project and …

That’s all – you can now test in both iOS 5.0 and iOS 4.3

All in all it’s about safe to support only 5.x when there’s a 5.1 release, by that time usually enough people have upgraded their devices (not counting the jail breakers of course, they update when there’s the relevant jail-break, but they are less likely to buy your app anyway…)

That’s it for today, more iOS5 posts to come.

0

How to detect the iPhone simulator?

-

Another quick tip: there are a bunch of defines which Apple provides you while your app is compiling and you can make great use of them. For example you whether the app will run on the device or in the simulator.

How to detect the iPhone simulator?

First of all, let’s shortly discuss. UIDevice provides you already information about the device

[[UIDevice currentDevice] model]

will return you “iPhone Simulator” or “iPhone” according to where the app is running.

However what you want is to use compile time defines. Why? Because you compile your app strictly to be run either inside the Simulator or on the device. Apple makes a define called  TARGET_IPHONE_SIMULATOR. So let’s look at the code :

#if TARGET_IPHONE_SIMULATOR

NSLog(@"Running in Simulator - no app store or giro");

#endif

It’s that easy. Now you can take care and maybe simulate some kind of input that lacks in the Simulator vs the device or other stuff you want to take care of.

NB: TARGET_OS_IPHONE

Now I’ve seen a ton of pages where some folks would just skim trough the Apple code find TARGET_OS_IPHONE and wrongly assume this define shows that the app is being compiled for the iPhone device. That’s wrong! I can’t believe there are even people complaining that Apple’s code is buggy because TARGET_OS_IPHONE is always 1.

Well let me put some light on that and please don’t make the same mistake. As the name of that define very clear explains this is a define which tells you whether the app is being compiled for the IPHONE OS ! Because even if most of the developers know only the iPhone development, actually XCode also provides development for the MAC OS X. So, if you are doing iPhone apps – yes! – TARGET_OS_IPHONE will be always 1.

How to detect the device

I feel this discussion will raise the question how to detect the device then. There’s 2 code samples you should use:

#if TARGET_IPHONE_SIMULATOR

NSLog(@"Running in Simulator - no app store or giro");

#else

NSLog(@"Running on the Device");

#endif

and when ONLY interested in the device

#if !(TARGET_IPHONE_SIMULATOR)

NSLog(@"Running on device");

#endif

So, hope this article was helpful. Please leave comments on ping me on Twitter.