我的应用程序创建了一个pdf文件,我想使用swift 3以编程方式将该pdf文档保存到iCloud Drive.
对于示例,我在这里使用了一个文本文件来保存在iCloud Drive中.
这是我的代码:
func copyDocumentsToiCloudDrive() {
var error: NSError?
let iCloudDocumentsURL = FileManager.default.url(forUbiquityContainerIdentifier: nil)?.appendingPathComponent("myCloudTest")
do{
//is iCloud working?
if iCloudDocumentsURL != nil {
//Create the Directory if it doesn't exist
if (!FileManager.default.fileExists(atPath: iCloudDocumentsURL!.path, isDirectory: nil)) {
//This gets skipped after initial run saying directory exists, but still don't see it on iCloud
try FileManager.default.createDirectory(at: iCloudDocumentsURL!, withIntermediateDirectories: true, attributes: nil)
}
} else {
print("iCloud is NOT working!")
// return
}
if …Run Code Online (Sandbox Code Playgroud) 这是我的应用程序的工作流程: 用户可以从应用程序的设置页面选择默认打印机,并且每次都会直接使用该默认打印机进行打印,而无需任何打印预览对话框。
我们可以使用以下方法选择打印机UIPrinterPickerController:
let printerPicker = UIPrinterPickerController(initiallySelectedPrinter: nil)
printerPicker.present(from: CGRect(x: 0, y: 0, width: 600, height: 500), in: self, animated: true) { (printerPicker, userDidSelect, error) in
if userDidSelect {
//Here get the selected UIPrinter
let defaultPrinter = printerPicker.selectedPrinter
}
}
Run Code Online (Sandbox Code Playgroud)
获取后UIPrinter,我们不能直接将UIPrinter对象保存到UserDefaults,这不是UserDefault支持类型。
是否有任何其他选项可以保存UIPrinter到用户默认值或任何其他方式来保存默认打印机。