【发布时间】:2014-10-10 02:30:40
【问题描述】:
我正在尝试在我的应用程序中创建一个 PDF,并且一切正常,除了当我在模拟器或设备上运行我的项目时,我在不会崩溃的代码行上得到一个异常断点该应用程序,但会生成 *** ImageIO - could not find ColorSync function 'ColorSyncProfileCreateSanitizedCopy' 的日志。继续执行后,我得到另一个异常断点,它仍然不会使应用程序崩溃,也不会产生任何输出。
这是我用来绘制 PDF 的代码:
+(void)drawText:(NSString *)textToDraw ofSize:(CGFloat)textSize inFrame:(CGRect)frameRect andRotate:(BOOL)shouldRotate
{
CFStringRef stringRef = (__bridge CFStringRef)textToDraw;
// Prepare the text using a Core Text Framesetter
CTFontRef font = CTFontCreateWithName (CFSTR("Helvetica"), textSize, NULL);
NSDictionary *attributes = @{ (__bridge id)kCTFontAttributeName : (__bridge id) font };
CFAttributedStringRef currentText = CFAttributedStringCreate(NULL, stringRef, (__bridge CFDictionaryRef)attributes);
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(currentText);
CGMutablePathRef framePath = CGPathCreateMutable();
CGPathAddRect(framePath, NULL, frameRect);
// Get the frame that will do the rendering.
CFRange currentRange = CFRangeMake(0, 0);
CTFrameRef frameRef = CTFramesetterCreateFrame(framesetter, currentRange, framePath, NULL);
CGPathRelease(framePath);
// Get the graphics context.
CGContextRef currentContext = UIGraphicsGetCurrentContext();
// Put the text matrix into a known state. This ensures
// that no old scaling factors are left in place.
CGContextSetTextMatrix(currentContext, CGAffineTransformIdentity);
// Core Text draws from the bottom-left corner up, so flip
// the current transform prior to drawing.
CGContextTranslateCTM(currentContext, 0, frameRect.origin.y*2);
CGContextScaleCTM(currentContext, 1.0, -1.0);
if(shouldRotate){
CGAffineTransform myTextTransform;
myTextTransform = CGAffineTransformMakeRotation (90 / 180.0 * M_PI);
CGContextSetTextMatrix (currentContext, myTextTransform);
}
// Draw the frame.
CTFrameDraw(frameRef, currentContext); //This is where the exception breakpoint stops
//*** ImageIO - could not find ColorSync function
//'ColorSyncProfileCreateSanitizedCopy'
CGContextScaleCTM(currentContext, 1.0, -1.0);
CGContextTranslateCTM(currentContext, 0, (-1)*frameRect.origin.y*2);
CFRelease(frameRef);
CFRelease(stringRef);
CFRelease(framesetter);
}
在我继续应用程序越过这些断点后,我会在此处获得更多异常断点:
libc++abi.dylib`__cxa_throw:
0x107726519: pushq %rbp //BREAKPOINT IS ON THIS LINE
0x10772651a: movq %rsp, %rbp
0x10772651d: pushq %r15
0x10772651f: pushq %r14
0x107726521: pushq %r12
0x107726523: pushq %rbx
0x107726524: movq %rdx, %r14
0x107726527: movq %rsi, %r15
0x10772652a: movq %rdi, %rbx
0x10772652d: callq 0x107726123 ; __cxa_get_globals
0x107726532: movq %rax, %r12
0x107726535: callq 0x107726ab0 ; std::get_unexpected()
0x10772653a: movq %rax, -0x60(%rbx)
0x10772653e: callq 0x107726aea ; std::get_terminate()
0x107726543: movq %rax, -0x58(%rbx)
0x107726547: movq %r15, -0x70(%rbx)
0x10772654b: movq %r14, -0x68(%rbx)
0x10772654f: leaq -0x20(%rbx), %r14
0x107726553: movabsq $0x434c4e47432b2b00, %rax
0x10772655d: movq %rax, -0x20(%rbx)
0x107726561: movq $0x1, -0x78(%rbx)
0x107726569: incl 0x8(%r12)
0x10772656e: leaq 0x1d(%rip), %rax ; __cxxabiv1::exception_cleanup_func(_Unwind_Reason_Code, _Unwind_Exception*)
0x107726575: movq %rax, -0x18(%rbx)
0x107726579: movq %r14, %rdi
0x10772657c: callq 0x107729448 ; symbol stub for: _Unwind_RaiseException
0x107726581: movq %r14, %rdi
0x107726584: callq 0x1077265b9 ; __cxa_begin_catch
0x107726589: movq -0x58(%rbx), %rdi
0x10772658d: callq 0x107726af9 ; std::__terminate(void (*)())
一旦我继续越过这些断点,实际上 PDF 就已创建,并且应用程序将继续按应有的方式运行。这些断点非常烦人,我不知道如何解决导致它们的问题。这发生在 iOS 8.0 及更高版本上。对此的任何帮助将不胜感激。
【问题讨论】:
-
我在 iOS 8 上遇到了同样的事情。我的所有异常断点不断在我使用 CGContextDrawPDFPage() 方法的行上中断,但它不会使应用程序崩溃。我还在控制台日志中看到了
*** ImageIO - could not find ColorSync function 'ColorSyncProfileCreateSanitizedCopy'。 -
我不太担心这个,因为应用程序不会崩溃,但我觉得在未来的版本中这会导致崩溃。
-
我遇到了同样的问题,但我没有处理 PDF... 我正在从文件扩展名为
.gif的目录中加载图像。显然它不喜欢那样,我只是去了一个.png文件。没有更多的错误。这可能只是文件的格式或压缩方式......不确定......我觉得你必须深入了解它的一些低级调试......特别是因为你处理核心框架 -
jsetting32 的评论给了我解决方案:我在使用 TIFF 文件时遇到了同样的问题。我将它转换为 PNG 并解决了它。
标签: ios pdf core-graphics runtime-error