My goal is to achieve compatibility across 3.x SDK versions for UIImagePickerController and it's allows(Image)Editing
property.
// SDK 2.0 to 3.0
myImagePickerController.allowsImageEditing = YES;
// SDK 3.1
myImagePickerController.allowsEditing = YES;
Some research reveals some objective-c approaches, but what is considered best practice for handling deprecated methods?
performSelector
orNSInvocation
for non-object arguments#define
approachAny other recommended strategies...开发者_运维百科
NSString * key = @"allowsEditing";
if ([myImagePickerController respondsToSelector:@selector(setAllowsImageEditing:)]) {
key = @"allowsImageEditing";
}
[myImagePickerController setValue:[NSNumber numberWithBool:YES] forKey:key];
wrap them in a @try @catch
block to ensure a working feature regardless of a deprecated method.
精彩评论