gpt4 book ai didi

ios - 仅生成 pdf : swift on 11. 3 的写入权限

转载 作者:行者123 更新时间:2023-11-28 06:00:40 24 4
gpt4 key购买 nike

我在 iOS 11.3 上生成 pdf 时出错。它在 iOS 11.2 上运行良好。

CGDataConsumerCreateWithFilename: failed to open `/note.pdf' for writing: Operation not permitted.
deflateEnd: error -3: (null).

Pdf 生成良好,但当我尝试访问它进行上传时,它会生成错误。相同的代码是:

let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]

let fileURL:URL = documentsURL.appendingPathComponent("note.pdf")

do {
try FileManager.default.createDirectory(atPath: fileURL.path, withIntermediateDirectories: true, attributes: nil)
} catch let error as NSError {
NSLog("Unable to create directory \(error.debugDescription)")
}

UIGraphicsBeginPDFContextToFile((fileURL.path as NSString).lastPathComponent as String?, CGRectZero, nil);

最后一行产生错误。

如有任何帮助,我们将不胜感激。

最佳答案

你把文件保存在根目录下,你不能这样做,试试这个

 let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]

let fileURL:URL = documentsURL.appendingPathComponent("note.pdf")

do {
try FileManager.default.createDirectory(atPath: fileURL.path, withIntermediateDirectories: true, attributes: nil)
} catch let error as NSError {
NSLog("Unable to create directory \(error.debugDescription)")
}

UIGraphicsBeginPDFContextToFile(fileURL.appendingPathComponent("note.pdf").path, CGRect.zero, nil);

Which will get and according to what you are doing you will create a folder note.pdf and then save the file note.pdf inside it

关于ios - 仅生成 pdf : swift on 11. 3 的写入权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49870962/

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