Core data 备份和恢复核心数据

Core data 备份和恢复核心数据,core-data,swift3,backup,ios10,restore,Core Data,Swift3,Backup,Ios10,Restore,我想让我的用户可以通过电子邮件备份他们的数据: let filemanager = FileManager() let documentsPath = NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask, true)[0] let coreDataFilePath = documentsPath.appending("/Application Support/MyApp.sqlite") let coreD

我想让我的用户可以通过电子邮件备份他们的数据:

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发生了变化。 我想在不需要用户重启应用程序的情况下完成所有这些

我将此帖子作为参考:

数据集有多大?电子邮件附件通常限制在10-20兆字节,在这个大小下,你可以像JSON一样轻松地获取所有内容和格式。菜鸟错误…:P我需要调查。有什么可以推荐的吗?