gpt4 book ai didi

iphone - 操作无法完成。 ( cocoa 错误 260。)

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:58:57 25 4
gpt4 key购买 nike

我是 IOS 开发的新手,我正在开发 pdf 应用程序,我需要将 PDF 文件存储在 NSData 变量上,我有 PDF 路径,但是当我尝试将此 pdf 放入时出现此消息错误在 NSData 变量上使用 dataWithContentsOfFile 她是我的简单代码:

NSError *error;
NSString *PdfPath = [NSString stringWithFormat:(@"%@"),document.fileURL ];
NSString *newPath = [PdfPath stringByReplacingOccurrencesOfString:@"file://localhost" withString:@""];
NSLog(@"OriginalPdfPath => %@", newPath);
NSData *pdfData = [NSData dataWithContentsOfFile:newPath options:NSDataReadingUncached error:&error];

注意:pdf 路径的格式为:/Users/bluesettle/Library/Application%20Support/iPhone%20Simulator/6.0/Applications/BBEF320E-7E2A-49DA-9FCF-9CFB01CC0402/ContractApp.app/Pro .iOS.Table.Views.pdf

谢谢你的帮助

最佳答案

Cocoa 错误 260 是 NSFileReadNoSuchFileError(如 FoundationErrors.h 中所列),这意味着无法在您指定的路径中找到该文件。

问题是您的路径仍然包含编码空格 (%20),因为您将它基于 URL。你可以简单地这样做:

NSData *pdfData = [NSData dataWithContentsOfFile:[document.fileURL path]];

关于iphone - 操作无法完成。 ( cocoa 错误 260。),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16394876/

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