Question

This is to be expected but I can't seem to find a runtime that works properly as it seems it was a private API before!!!!

At the moment I have and OS3.1.3 responds to the addGestureRecognizer selector!!!!

if ( [self.view respondsToSelector:@selector(addGestureRecognizer:)] ) {

        UIGestureRecognizer *recognizer;
        recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(morePress)];
        [self.view addGestureRecognizer:recognizer];
        recognizer.delegate = self;
        [recognizer release];


    }
Was it helpful?

Solution

You should check for the system version explicitly:

NSString *currentSystemVersion = [[UIDevice currentDevice] systemVersion];
if([currentSystemVersion compare:@"3.2"] == NSOrderedAscending) {
    //add gesture recognizer
} else {
    // :(
}

OTHER TIPS

UIGestureRecognizer is not supported prior to iOS 3.2. Even if the method addGestureRecognizer: exists, that doesn't mean it's safe to use.

It was indeed a private api and not supported in versions prior to 3.2.

Apple's doc says:

To determine at runtime whether you can use gesture recognizers in your application, test whether the class exists and, if it does, allocate an instance and see check if it responds to the selector locationInView:. This method was not added to the class until iOS 3.2.

Sample code:

UIGestureRecognizer *gestureRecognizer = [[UIGestureRecognizer alloc] initWithTarget:self action:@selector(myAction:)];

if (![gestureRecognizer respondsToSelector:@selector(locationInView:)]) {
    [gestureRecognizer release];
    gestureRecognizer = nil;
}
// do something else if gestureRecognizer is nil

Explenation:

To determine whether a class is available at runtime in a given iOS release, you typically check whether the class is nil. Unfortunately, this test is not cleanly accurate for UIGestureRecognizer. Although this class was publicly available starting with iOS 3.2, it was in development a short period prior to that. Although the class exists in an earlier release, use of it and other gesture-recognizer classes are not supported in that earlier release. You should not attempt to use instances of those classes.

Check out the full text here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top