0

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?

James Z
  • 12,209
  • 10
  • 24
  • 44
poojathorat
  • 1,200
  • 2
  • 9
  • 19
  • How big is the file before attaching it to your mail composer? – Leo Dabus Jul 15 '21 at 05:58
  • upto 10 MB.As we are taking readings,Images in app & storing them,size may increase.Is there any other way than mail as well ? – poojathorat Jul 15 '21 at 06:12
  • most mail can't deal with message attachments bigger than 10MB-20MB. You can allow them to save it locally, dropbox, iCloud or somewhere else using Files app. If you have a server you can upload the file and specify a larger limit – Leo Dabus Jul 15 '21 at 06:42
  • instead of attaching SQLite file directly, you can try compressing it in a zip file. – Manish Punia Jul 15 '21 at 06:50
  • 1
    The empty file is probably down to WAL mode - see [here](https://stackoverflow.com/a/23090939/3985749) or search SO for Core-Data WAL for an explanation. – pbasdf Jul 15 '21 at 07:30
  • Does this answer your question? [Found empty data in sqlite when send via MFMailcomposeController](https://stackoverflow.com/questions/56151110/found-empty-data-in-sqlite-when-send-via-mfmailcomposecontroller) – pbasdf Jul 19 '21 at 08:32

0 Answers0