ios开发的系统兼容性问题解决

对于系统中过时的方法或者是为了向下兼容兼容不同的版本使用最新的方法都要判断当前的系统版本号,在进行方法的调用

1.系统方法过时的注释

````objc

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo NS_DEPRECATED_IOS(2_0, 3_0);

说明方法在2.0时代引入,3.0时代过时

````

2.系统不同版本方法的兼容性解决方案(这个比较好,不会产生警告)

````objc

#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_5_0
    if([picker respondsToSelector:@selector(dismissModalViewControllerAnimated:)]){
        [picker dismissModalViewControllerAnimated:YES completion:nil];
    }
    else
#endif
    {
        [picker dismissViewControllerAnimated:YES completion:nil];
    }

````

 

3.系统不同版本方法的兼容性解决方案2(书写方便,但是会产生警告)

````objc

if([picker respondsToSelector:@selector(imagePickerController:didFinishPickingMediaWithInfo:)]){
    [picker dismissViewControllerAnimated:YES completion:nil];
}else{
    [picker dismissModalViewControllerAnimated:YES];
}
````

posted @ 2016-01-22 14:37  蓝色的风1203  阅读(1223)  评论(0编辑  收藏  举报