我正在维护一些其他人编写的代码,当我在 Xcode 4.5 上构建并在 iOS 6 上运行时,我得到了这个运行时“错误”
<Error>: The function `CGCMSUtilsGetICCProfileDataWithRenderingIntent' is obsolete and will be removed in an upcoming update. Unfortunately, this application, or a library it uses, is using this obsolete function, and is thereby contributing to an overall degradation of system performance. Please use `CGColorSpaceCopyICCProfile' instead.
执行此代码时:
CGColorSpaceRef alternate = CGColorSpaceCreateDeviceRGB();
NSString *iccProfilePath = [[NSBundle mainBundle] pathForResource:@"sRGB Profile" ofType:@"icc"];
NSData *iccProfileData = [NSData dataWithContentsOfFile:iccProfilePath];
CGDataProviderRef iccProfile = CGDataProviderCreateWithCFData((CFDataRef)iccProfileData);
const CGFloat range[] = {0,1,0,1,0,1}; // min/max of the three components
CGColorSpaceRef colorSpace = CGColorSpaceCreateICCBased(3, range, iccProfile, alternate);
CGContextRef context = CGBitmapContextCreate(NULL, pageWidth, pageHeight, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast);
CGDataProviderRelease(iccProfile);
CGColorSpaceRelease(colorSpace);
CGColorSpaceRelease(alternate);
当我在 iOS 5.1 上运行时没有错误。
我发现通过进行以下更改不会出现错误:
改变:
NSString *iccProfilePath = [[NSBundle mainBundle] pathForResource:@"sRGB Profile" ofType:@"icc"];
NSData *iccProfileData = [NSData dataWithContentsOfFile:iccProfilePath];
CGDataProviderRef iccProfile = CGDataProviderCreateWithCFData((CFDataRef)iccProfileData);
至:
char fname[]= "sRGB Profile.icc";
CGDataProviderRef iccProfile = CGDataProviderCreateWithFilename(fname);
我找不到任何对已弃用的CGDataProviderCreateWithCFData的引用。谁能解释问题的原因?似乎CGDataProviderCreateWithCFData正在使用CGCMSUtilsGetICCProfileDataWithRenderingIntent并且CGDataProviderCreateWithFilename正在使用CGColorSpaceCopyICCProfile,这表明CGDataProviderCreateWithCFData已被弃用。我对找到的解决方案感到不舒服,因为我不明白这一点。另外,我希望该解决方案对某人有所帮助。