相关疑难解决方法(0)

CGPDFDocumentCreateWithURL失败(NSURL到CFURLRef的免费桥接)

我有以下功能:

- (void)loadPdfFromPath:(NSString*)path
{   
    NSURL *pathUrl = [NSURL URLWithString:path];

    _pdfDocument = CGPDFDocumentCreateWithURL((CFURLRef)pathUrl);
}
Run Code Online (Sandbox Code Playgroud)

从我带领相信会工作,因为你可以从一个区分的文件NSURL*到一个CFURLRef通过免费电话桥接.但是,此函数失败,我在日志中得到以下输出:

CFURLCreateDataAndPropertiesFromResource:错误代码-15.

注意:-15 = kCFURLImproperArgumentsError

但是,如果我创建一个实际的CFURLRef,它的工作绝对正常:

- (void)loadPdfFromPath:(NSString*)path
{
    CGPDFDocumentRelease(_pdfDocument);

    CFStringRef cgPath = CFStringCreateWithCString(NULL, [path UTF8String], kCFStringEncodingUTF8);

    CFURLRef url = CFURLCreateWithFileSystemPath(NULL, cgPath, kCFURLPOSIXPathStyle, 0);

    _pdfDocument = CGPDFDocumentCreateWithURL(url);

    CFRelease(url);
    CFRelease(cgPath)
}
Run Code Online (Sandbox Code Playgroud)

我错过了什么?我很高兴在我的代码中保留第二个函数,但我宁愿知道为什么第一个函数失败了.

pdf xcode core-graphics objective-c

0
推荐指数
1
解决办法
1545
查看次数

标签 统计

core-graphics ×1

objective-c ×1

pdf ×1

xcode ×1