我有这个应用程序,它将在iCloud.plist
中创建文件备份。在我的测试设备(iPhone XR)中进行测试后,它可以顺利备份,但在使用不同的测试设备(如iPhone 6s plus、iPhone 5s和5 )时。它不保存任何数据。它会自动跳转到警告控制器没有数据要保存。请参考下面的代码。请告诉我我错过了导致错误的代码部分。请帮助我解决这个问题将近 2 周,但我仍然没有找到任何解决方案。谢谢
//the storage location of the plist you want to save
let strLibraryPath = NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask, true)[0]
let strPlistPath = "\(strLibraryPath)/\(S_DIRECTORY_NAME)/\(S_PLIST_NAME)"
localURL = URL(fileURLWithPath: strPlistPath)
//judge if there is plist to save
let aFileManager = FileManager.default
if !aFileManager.fileExists(atPath: strPlistPath) {
let alertController = UIAlertController(title: "", message: "保存するデータがありません \n (No data to save)", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "OK", style: .default))
self.present(alertController, animated: true, completion: nil)
}
else {
blYesNoAlert = true
let alert = UIAlertController(title: "Confirmation", message: "バックアップを作成しますか?\n (Do you want to make a backup?)", preferredStyle: UIAlertController.Style.alert)
alert.addAction(UIAlertAction(title: "いいえ", style: UIAlertAction.Style.default, handler: { _ in
//Cancel Action
}))
alert.addAction(UIAlertAction(title: "はい",
style: UIAlertAction.Style.default,
handler: {(_: UIAlertAction!) in
Timer.scheduledTimer(timeInterval: 0.5, target: self, selector: #selector(self.backupData), userInfo: nil, repeats: false)
}))
self.present(alert, animated: true, completion: nil)
}
}