2

I've been working on iPhone app for awhile and still want to support 2.2.1

One of the features is that the user can start the app via email by clicking a link. In the 2.2.1 world, I accomplished this by implemting the application: handleOpenURL: message.

In iPhone 3.0, they've changed things up adding the application: didFinishLaunchingWithOptions: method (which is great, and makes a lot more sense than the old way). In that method, you use the key UIApplicationLaunchOptionsURLKey to find out what the URL was.

The problem is, if I use that key my app doesn't build in 2.2.1 since it was introduced in 3.0. What's the most elegant way to get around this and still support 2.2.1? I was thinking of using the actual value for the UIApplicationLaunchOptionsURLKey enum, but I figured that was ugly. Has anybody encountered this and think of a better way?

Quinn Taylor
  • 44,553
  • 16
  • 113
  • 131
bpapa
  • 21,409
  • 25
  • 99
  • 147

6 Answers6

1

The simplest way is to #define around the 3.0 code and 2.2.1 code so you can do conditional compilation. Note: This means you will have one binary for 3.0 and another for the other.

so

#ifdef IPHONE_OS_3.0

/* DO 3.0 stuff */

#endif

#ifdef IPHONE_OS_2.2.1

/*DO 2.2.1 stuff */
#endif

In response to your comment, you would have to have a different #ifdef #endif for each code block if the code is going to be different, otherwise if it is only different for 3.0 you would do something like

#ifdef IPHONE_OS_3.0

/* DO 3.0 STUFF */

#else
/* DO STUFF FOR OTHER THAN 3.0 */
#endif

You are going to have to figure out what the real definitions are (I just made them up :))

Hope that helps

hhafez
  • 38,949
  • 39
  • 113
  • 143
1

Use the 3.0 SDK, but set the "iPhone OS Deployment Target" to 2.2.1 or earlier.

Under OS 3.0, your application: didFinishLaunchingWithOptions: will get called, and if you're running on OS 2.2.1, one of the old methods will get called.

If you're not trying to use any other 3.0 features, I don't think you'll need to do anything else, but you could also look at my other answer about Apple's MailComposer sample.

Community
  • 1
  • 1
David Maymudes
  • 5,664
  • 31
  • 34
0

There's a question about 3.0 features in 2.0 iPhone OS. But you want to know (at run time) if a symbol exits in the UIKit or whereever. I'm afraid, that's not answered there, yet.

Community
  • 1
  • 1
Nikolai Ruhe
  • 81,520
  • 17
  • 180
  • 200
0

To have a single app that works on both OS versions, you have to build against the 2.2.1 SDK. And since that SDK has no idea the UIApplicationLaunchOptionsURLKey symbol, you have no choice but to define it in your code if you recognise it value when your app is run on OS 3.0.

On the other hand, adoption of OS 3.0 is very strong (upwards of 75% already, according to one figure I've seen), so making your app OS 3.0 only is also a solution to consider.

grahamparks
  • 16,130
  • 5
  • 49
  • 43
0

So what should you too if you want to have a single binary that supports multiple OS versions? I'm especially stuck on how to conditionally load the necessary libraries for 3.0.

-1
#ifdef __IPHONE_3_0
// iPhone 3.0 specific stuff
#else
// iPhone 2.2 (or below) specific stuff
#endif
micmoo
  • 5,991
  • 3
  • 22
  • 16