我试图在我的应用中创建一个PDF,一切正常,但是当我在模拟器或设备上运行我的项目时,我在一行代码上得到一个异常断点&# 39; t崩溃应用程序,但生成*** 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及更高版本上。对此的任何帮助将不胜感激。
答案 0 :(得分:1)
解决。避免使用CTFrameDraw(frameRef,currentContext)或drawPageAtIndex:inRect :.并使用核心图形方式手动生成pdfs。它似乎是iOS 8或更高版本中未记录的错误。
有关详细信息,请参阅http://pigfly.github.io/blog/2014/11/11/road-to-ios-0-dot-x/