gpt4 book ai didi

iphone - NSString 不会转换为 NSURL(NSURL 为空)

转载 作者:可可西里 更新时间:2023-11-01 05:04:10 33 4
gpt4 key购买 nike

我正在尝试将 NSString(文档目录中文件的路径)转换为 NSURL,但 NSURL 始终为空。这是我的代码:

NSURL *urlToPDF = [NSURL URLWithString:appDelegate.pdfString];
NSLog(@"AD: %@", appDelegate.pdfString);
NSLog(@"PDF: %@", urlToPDF);
pdf = CGPDFDocumentCreateWithURL((CFURLRef)urlToPDF);

这是日志:

2012-03-20 18:31:49.074 The Record[1496:15503] AD: /Users/John/Library/Application Support/iPhone Simulator/5.1/Applications/E1F20602-0658-464D-8DDC-52A842CD8146/Documents/issues/3.1.12/March 1, 2012.pdf
2012-03-20 18:31:49.074 The Record[1496:15503] PDF: (null)

我认为部分问题可能是 NSString 包含斜杠/和破折号 -。我做错了什么?谢谢。

最佳答案

为什么不以这种方式创建文件路径。

NSString *filePath = [[NSBundle mainBundle]pathForResource:@"pdfName" ofType:@"pdf"];

然后用这样的文件路径创建你的 url。

NSURL *url = [NSURL fileURLWithPath:filePath];

关于iphone - NSString 不会转换为 NSURL(NSURL 为空),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9796023/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com