gpt4 book ai didi

ios - 写入: Operation not permitted issue while working pdf

转载 作者:行者123 更新时间:2023-12-02 02:29:11 28 4
gpt4 key购买 nike

我正在研究 PDF 文件以使用 Core Text 进行读写。下面的代码是在PDF文件上绘制内容。

let fileName = "pdffilename.pdf"
let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
let documentsDirectory = paths[0] as NSString
let pathForPDF = documentsDirectory.stringByAppendingString(fileName)
UIGraphicsBeginPDFContextToFile(pathForPDF, CGRectZero, nil)
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0,612,792), nil)
pagedataforPortaits()
UIGraphicsEndPDFContext()

这段代码在模拟器上运行得非常好,但是当我使用真实设备时,我收到错误

<Error>: CGDataConsumerCreateWithFilename: failed to open `/var/mobile/Containers/Data/Application/CADA69EB-8879-45EE-BBE0-477AC810BB86/Documentspdffilename.pdf' for writing: Operation not permitted.
deflateEnd: error -3: (null).
deflateEnd: error -3: (null).
<Error>: CGPDFContextCreate: failed to create PDF context delegate.

有什么建议吗?

最佳答案

路径字符串需要在文档目录和文件名之间使用“/”分隔符。

Swift 5.1:

let fileName = "pdffilename.pdf"
let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
let documentsDirectory = paths[0]
let pathForPDF = documentsDirectory + "/" + fileName

关于ios - 写入: Operation not permitted issue while working pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39481439/

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