How to get my iOS4.2 SDK developed code working with iOS3.1.3?

407 Views Asked by At

I am new to iPhone development. I started developing a project using iOS4.2 SDK. It works properly on both an iOS4.2 device and simulator. Later I realized that my app wasn't working on devices with iOS3.1.3. To solve this I updated the "Deployment Target" in my app's configuration file to "3.1.3".

The problem I am having is that I use UITapGestureRecognizer in some of my classes. On compiling my code using iOS 3.1.3 SDK I get the following errors:

error: 'UITapGestureRecognizer' undeclared (first use in this function)

error: 'tap' undeclared (first use in this function)

From what I have ready, this seems to be because iOS .1.3 does not support UITapGestureRecognizer, so to run this i made the following changes wherever I use UITapGestureRecognizer:

Class mailClass = (NSClassFromString(@"UITapGestureRecognizer"));
if(mailClass != nil)
{
 UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(findOutTheTagmap:)];
 [imageView addGestureRecognizer:tap];
 [tap release];
}

I also updated my Target configuration and set the UIKit Framework to "Weak". Additionally I have also made the following changes: Base SDK: 3.1.3 Compiler Version: GCC4.2 (also tried with GCC4.0) Mac OS X Deployment Target: Compiler Default (also tried with 10.4 and 10.6) iOS Deployment Target: 3.1.3

Yet, when I try compiling my code, I am still shown the same errors. What is surprising is that a few days ago someone was helping me and this worked.

I have tried pretty much everything I have found in forums.

Does anyone have an idea on how I can proceed?

Thanks in advance!

2

There are 2 best solutions below

0
On

Setting a different SDK as you've done can be useful for getting hard errors about what you can't use, but as you can see it's difficult to impossible (depending on the class) to work around.

Instead, you should always be building against the latest SDK. (In fact, newer versions of Xcode have a "latest" setting you should use.) Set iOS Deployment Target (IPHONEOS_DEPLOYMENT_TARGET) to your minimum version.

0
On

Base SDK is the version of the SDK used to compile your application. You need to make sure it's set to a version that has all the features you're using. UIGestureRecognizer requires 3.2 or later, so you should set your Base SDK 3.2 or later. And actually, 3.2 was iPad only; if your app is for iPhone, you'll need to set Base SDK to 4.0 or later. 3.1.3 for the Deployment Target is correct. Check your code to make sure there aren't other classes you're using which aren't available in 3.1.3 (check the docs).

Matt Gallagher has a great article on this which I highly recommend, here. While you're there, read his whole blog, it's great. :)