1

I have an application designed for iPhone OS 2.0 and I am adding some new 3.x functionality to it. My idea is to maintain compatibility with older versions.

I have managed so far, to test for deprecated functions using "if respondToSelector...". This is just fine for calls inside a method but how to deal with method name changes? For example, the OS 2.x method

-imagePickerController:didFinishPickingImage:editingInfo:

changed in OS 3.x to

-imagePickerController:didFinishPickingMediaWithInfo:

How can I test for the OS version and direct the application to the proper method in this case?

thanks for any help.

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
Duck
  • 34,902
  • 47
  • 248
  • 470
  • FWIW, most iPhone devs don't bother with supporting 2.x anymore. The number of iPhone/Touch users still running 2.x is practically insignificant, and those who are probably don't download apps from the App Store. – Kristopher Johnson Mar 07 '10 at 18:12
  • 2
    The number of iPod Touch users still running 2.0 is 32%, according to AdMob. I would't call this insignificant. – Duck Mar 07 '10 at 18:38
  • 1
    Those statistics were for users of Admob-ad-supported applications as of December. In the meantime, a huge number of new iPod touch devices were sold over Christmas, all running iPhone OS 3.0, and the upgrade price was dropped to $5. Handicapping yourself by chasing after the cheapskates who won't upgrade doesn't seem wise at this point. Not once has anyone complained about my applications being 3.0-only. – Brad Larson Mar 07 '10 at 20:20
  • this is not the point. The point is that many users bought my App since 2.0 and changing to 3.0 will left this users in the cold and they could not receive any application upgrade after that. – Duck Mar 08 '10 at 02:23
  • 1
    After a second read, I found, that I did not get your problem completely. If you implement both methods, either one will be performed at runtime. If it is a 2.x the -imagePickerController:didFinishPickingImage:editingInfo: will be performed, if it is 3.x the other one will be called. Isn't that everything you want? – maxbareis Mar 08 '10 at 07:06
  • duuuuhhhh... obviously! Sometimes the obvious is hard to see! If yo make this an answer, I can give you the points. :-) Thanks!!!!!!!!!!!!!!! – Duck Mar 08 '10 at 18:13

2 Answers2

3

You can use NSObject's -respondsToSelector method to dynamically determine if the method exists, then call it. You might also want to use -performSelector:withObject: to call the methods, so you don't get compiler warnings.

Grant Paul
  • 5,852
  • 2
  • 33
  • 36
  • If you read what I said you will see that this method I am talking about is called automatically by the delegate (or in the delegate). – Duck Mar 08 '10 at 02:25
  • Oh, for that just implement both and have them just call a third, internal method. The unused one is not harmful. – Grant Paul Mar 09 '10 at 05:51
  • In the case of a deprecated method, *both* the old/new variants are available. So let's my base SDK is 4.0, and the deployment target is 3.0 (which a significant number of my customers will have for the interim, if the 2.0-to-3.0 upgrade period was any indication - free upgrades this go-round notwithstanding), using -respondsToSelector: won't help here, nor will #if/#else tests ... will they? Or do I have to get the iOS version at runtime? (Shudder.) – Joe D'Andrea Jun 21 '10 at 19:28
  • Yeah, I'd grab it from UIDevice. – Grant Paul Jun 21 '10 at 21:18
0

OK.

After a second read, I found, that I did not get your problem completely. If you implement both methods, either one will be performed at runtime. If it is a 2.x the -imagePickerController:didFinishPickingImage:editingInfo: will be performed, if it is 3.x the other one will be called

This is the crap I have written prematurely and where the comments are related to:

you may use

#ifdef __IPHONE_3_0
// iPhone 3.0 specific stuff
#else
// iPhone 2.2 specific stuff
#endif

see also this post:

What #defines are set up by Xcode when compiling for iPhone

Community
  • 1
  • 1
maxbareis
  • 886
  • 9
  • 17
  • This only works at compile-time and will not do what he wants. If he's compiling for 3.x, but targeting 2.x, it will build the 3.x code which will fail on a 2.x device. – Brad Larson Mar 07 '10 at 20:21