如何将NSString路径转换为CFURLRef(对于iOS 3.1)?

| 我在UIScrollView中显示PDF。为此,我使用:
myDocumentRef = CGPDFDocumentCreateWithURL((CFURLRef)[[NSBundle mainBundle] URLForResource:@\"salonMap\" withExtension:@\"pdf\"]);
现在,我尝试使其在IOS 3.1上运行(NSBundle URLForResource:withExtension对于3.1不存在) 我将代码转换为:
NSString *fullPath =  [[NSBundle mainBundle] pathForResource:@\"salonMap\" ofType:@\"pdf\"];
NSLog(@\"%@\", fullPath);
CFStringRef fullPathEscaped = CFURLCreateStringByAddingPercentEscapes(NULL,(CFStringRef)fullPath, NULL, NULL,kCFStringEncodingUTF8);
CFURLRef urlRef = CFURLCreateWithString(NULL, fullPathEscaped, NULL);
myDocumentRef = CGPDFDocumentCreateWithURL(urlRef);
但这导致
<Error>: CFURLCreateDataAndPropertiesFromResource: failed with error code -15
我精确地说,NSLog日志
/var/mobile/Applications/1CF69390-85C7-45DA-8981-A279464E3249/myapp.app/salonMap.pdf\"
我该如何解决?     
已邀请:
借助免费的桥接功能,NSURL可与CFURLRef互换。尝试这个:
NSString *pdfPath = [[NSBundle mainBundle] 
                     pathForResource:@\"salonMap\" ofType:@\"pdf\"];
NSURL *pdfUrl = [NSURL fileURLWithPath:pdfPath];
CGPDFDocumentRef pdfRef = CGPDFDocumentCreateWithURL((CFURLRef)pdfUrl);
    
重要的是要提一下,如果您使用的是ARC,它将不再起作用。结果,您将需要创建一个桥接演员表。见下文:
NSString *pdfPath = [[NSBundle mainBundle] 
                 pathForResource:@\"salonMap\" ofType:@\"pdf\"];
NSURL *pdfUrl = [NSURL fileURLWithPath:pdfPath];
CGPDFDocumentRef pdfRef = CGPDFDocumentCreateWithURL((__bridge CFURLRef)pdfUrl);
    

要回复问题请先登录注册