Checking if UIGraphicsBeginImageContextWithOptions is supported

后端 未结 3 865
时光说笑
时光说笑 2021-01-13 02:27

I\'m working on an iOS app. It currently only works on iOS 4 since I use the following method on several occasions: \"UIGraphicsBeginImageContextWithOptions\". This method i

相关标签:
3条回答
  • 2021-01-13 02:58

    I know this is an old question, but with new Xcode and iOS versions (upper than 9) any of this methods work for me.

    I always check the system version in this way:

    NSString *sysver = [[UIDevice currentDevice] systemVersion];
    NSArray *versionNums = [sysver componentsSeparatedByString:@"."];
    int majorVersion = [versionNums[0] intValue];
    if (majorVersion > 3){
        UIGraphicsBeginImageContextWithOptions(...);
    }
    else{
        UIGraphicsBeginImageContext(...);
    }
    

    I hope this could help anyone.

    0 讨论(0)
  • 2021-01-13 03:17

    I have the same problem. You could try testing the system version. This seems to work for me on the devices I tested.

    char majorVersion = [[[UIDevice currentDevice] systemVersion] characterAtIndex: 0];
    if (majorVersion == '2' || majorVersion == '3')
         UIGraphicsBeginImageContext(...);
    else
         UIGraphicsBeginImageContextWithOptions(...);
    
    0 讨论(0)
  • 2021-01-13 03:23

    UIGraphicsBeginImageContextWithOptions is a C function, so you can't use Objective-C methods like -respondsToSelector: to test its existence.

    You could, however, weak link the UIKit framework, and then check if UIGraphicsBeginImageContextWithOptions is NULL:

    if (UIGraphicsBeginImageContextWithOptions != NULL) {
       UIGraphicsBeginImageContextWithOptions(...);
    } else {
       UIGraphicsBeginImageContext(...);
    }
    
    0 讨论(0)
提交回复
热议问题