I am trying to export Core Data Local Sqlite Database from iPhone to System through mail. I can see .sqlite database as attachment. But it is empty, no data in any table.
I am doing this with below code.
if MFMailComposeViewController.canSendMail(){
let composer = MFMailComposeViewController()
composer.setToRecipients(["test@gmail.com"])
composer.setSubject("Sending Local Database File")
composer.setMessageBody("Hello,\nPlease find the attached local database file in this email.\n and Kindly check it and let us know.", isHTML: false)
composer.mailComposeDelegate = self
let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
let fileURL = documentsDirectory.appendingPathComponent("Project.sqlite")
print("Database File URL is - \(fileURL)")
do {
let attachmentData = try Data(contentsOf: fileURL)
composer.addAttachmentData(attachmentData, mimeType: "application/x-sqlite3", fileName: "Project.sqlite")
self.present(composer, animated: true)
} catch {
print(error)
}
}
Or is there any way to export core data sqlite database from app other than connecting device to MAC or Any system through cable (except iTunes/XCode)? can we export it directly from app?