4

The latest Xcode IDE requires you to target iPhone SDK 4 while dynamically handling deprecated and new functionality if you set the application to deploy to earlier releases.

So can I use new features like Blocks and still have it work on a device running iPhone OS 3.0 or 3.1 or 3.1.3?

I have not found documentation on how to do backward compatibility for previous iPhone OS versions. If you could point me to official docs which cover how this should be done I'd appreciate it.

Brennan
  • 11,546
  • 16
  • 64
  • 86

4 Answers4

4

As far as I know, blocks won't work pre-3.2 because the Blocks runtime is not included (classes like __NSStackBlock__ or whatever). Other than that, my understanding is that you can compile code with blocks if you use a new enough compiler. A solution would be to include a custom blocks runtime conditionally with your project.

Jonathan Sterling
  • 18,320
  • 12
  • 67
  • 79
3

While the easiest thing to do is try it, I think that they wont cause harm if present but not used (eg. you use a runtime if statement to circumvent the blocks using code on pre-4.0 devices), but they will certainly not run on pre-4.0 devices, and all of the APIs Apple provides that use blocks will be unavailable anyway. All in all, if you have a way to do something without blocks, there is no reason to have a different way to do it with blocks -- this just increases redundancies and duplicated code -- therefore if you wish to target pre-4.0 devices, you should not use blocks, but if you want/need to use blocks, don't target OSes below 4.0

Jared Pochtar
  • 4,925
  • 2
  • 29
  • 39
0

Use preprocessor directives (http://developer.apple.com/iphone/library/documentation/xcode/conceptual/iphone_development/115-Configuring_Applications/configuring_applications.html) such as TARGET_OS_IPHONE to use code for different iOS versions.

Alex Reynolds
  • 95,983
  • 54
  • 240
  • 345
0

No, blocks won't work on iPhone pre-3.2 without PLBlocks — and even then, whatever method is taking the block might not exist.

Noah Witherspoon
  • 57,021
  • 16
  • 130
  • 131
Chuck
  • 234,037
  • 30
  • 302
  • 389