如何使用(可能是非对象)参数解决已弃用的属性/方法?

时间:2009-10-25 18:38:53

标签: iphone objective-c

我的目标是实现针对UIImagePickerController的3.x SDK版本的兼容性及其allows(Image)Editing属性。

// SDK 2.0 to 3.0
myImagePickerController.allowsImageEditing = YES;

// SDK 3.1
myImagePickerController.allowsEditing = YES;

一些研究揭示了一些客观方法,但处理弃用方法的最佳做法是什么?

    对于非对象参数,
  1. performSelectorNSInvocation

  2. #define方法

  3. 任何其他推荐策略......

2 个答案:

答案 0 :(得分:9)

NSString * key = @"allowsEditing";
if ([myImagePickerController respondsToSelector:@selector(setAllowsImageEditing:)]) {
  key = @"allowsImageEditing";
}
[myImagePickerController setValue:[NSNumber numberWithBool:YES] forKey:key];

答案 1 :(得分:-1)

将它们包装在@try @catch块中,以确保工作功能,无论是否弃用方法。