我想为我的用户提供电子邮件备份数据的可能性:
let filemanager = FileManager()
let documentsPath = NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask, true)[0]
let coreDataFilePath = documentsPath.appending("/Application Support/MyApp.sqlite")
let coreDataFile = filemanager.contents(atPath: coreDataFilePath)
print("\(coreDataFilePath)")
if MFMailComposeViewController.canSendMail()
{
let mail = MFMailComposeViewController()
mail.mailComposeDelegate = self
mail.setSubject("Backup")
mail.setMessageBody("Use this email to backup your data", isHTML: true)
mail.addAttachmentData(coreDataFile!, mimeType: "myapp/sqlite", fileName: "myapp.madb")
present(mail, animated: true, completion: nil)
}
else
{
print("Mail services are not available. Please open the mail application and setup an email account.")
return
}
但我想恢复数据,不知道应该怎么做。特别是iOS 10 CoreData发生了变化。 我想完成所有这些操作,而无需用户重新启动应用程序。
我有这篇文章作为参考: Best practices for core data store (sqlite) backup?