iOS 16 中 iCloud 存储与文档浏览器的使用
1. 使用 iCloud 存储
在 iOS 16 应用中使用 iCloud 存储时,若文档存在,读取文档会触发调用文档对象的 load(fromContents:) 方法,该方法会将文档内容赋值给 userText 属性。若文档读取成功,需将 userText 的值赋给文本视图对象的 text 属性,使内容对用户可见。以下是相应代码片段:
document = MyDocument(fileURL: resultURL as URL)
document?.open(completionHandler: {(success: Bool) -> Void in
if success {
print("iCloud file open OK")
self.textView.text = self.document?.userText
self.ubiquityURL = resultURL as URL
} else {
print("iCloud file open failed")
}
})
若文档在 iCloud 存储中不存在,则需使用文档对象的 save(to:) 方法创建文档,将 ubiquityURL 作为 iCloud 上的目标路径:
超级会员免费看
订阅专栏 解锁全文
22

被折叠的 条评论
为什么被折叠?



