ios - Zip file doesn't arrive when attached to email -



ios - Zip file doesn't arrive when attached to email -

im trying zip sqlite files documents directory send via mail service using https://github.com/mattconnolly/ziparchive.

nsstring *filepath = [[nshomedirectory() stringbyappendingpathcomponent:@"documents"] stringbyappendingpathcomponent:@"app.sqlite"]; nsstring *filepath2 = [[nshomedirectory() stringbyappendingpathcomponent:@"documents"] stringbyappendingpathcomponent:@"app.sqlite-shm"]; nsstring *filepath3 = [[nshomedirectory() stringbyappendingpathcomponent:@"documents"] stringbyappendingpathcomponent:@"app.sqlite-wal"]; nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *documentsdirectory = [paths objectatindex:0]; nsstring *archivepath = [documentsdirectory stringbyappendingstring:@".zip"]; //zip files ziparchive *archiver = [[ziparchive alloc] init]; [archiver createzipfile2:archivepath]; [archiver addfiletozip:filepath newname:@"backup.sqlite"]; [archiver addfiletozip:filepath2 newname:@"backup.sqlite-shm"]; [archiver addfiletozip:filepath3 newname:@"backup.sqlite-wal"]; mfmailcomposeviewcontroller *mailview = [[mfmailcomposeviewcontroller alloc] init]; if (mailview != nil) { mailview.mailcomposedelegate = self; [mailview setsubject:@"database"]; //attach zip file [mailview addattachmentdata:[nsdata datawithcontentsoffile:archivepath] mimetype:@"application/zip" filename:@"test.zip"]; [mailview setmessagebody:@"database attached" ishtml:no]; [self presentviewcontroller:mailview animated:yes completion: null]; }

the attachment appears in email preview on device when arrives recipient attachment has vanished?

also tried this:

nsstring *filepath = [[nshomedirectory() stringbyappendingpathcomponent:@"documents"] stringbyappendingpathcomponent:@"app.sqlite"]; nsstring *filepath2 = [[nshomedirectory() stringbyappendingpathcomponent:@"documents"] stringbyappendingpathcomponent:@"app.sqlite-shm"]; nsstring *filepath3 = [[nshomedirectory() stringbyappendingpathcomponent:@"documents"] stringbyappendingpathcomponent:@"app.sqlite-wal"]; debuglog(@"db path is: %@", filepath); nserror *error = nil; nsdata *filedata = [[nsdata alloc] initwithcontentsoffile:filepath options:0ul error:&error]; nsstring* filedatastring = [[nsstring alloc] initwithdata:filedata encoding:nsnonlossyasciistringencoding]; nsdata *filedata2 = [[nsdata alloc] initwithcontentsoffile:filepath2 options:0ul error:&error]; nsstring* filedata2string = [[nsstring alloc] initwithdata:filedata2 encoding:nsnonlossyasciistringencoding]; nsdata *filedata3 = [[nsdata alloc] initwithcontentsoffile:filepath3 options:0ul error:&error]; nsstring* filedata3string = [[nsstring alloc] initwithdata:filedata3 encoding:nsnonlossyasciistringencoding]; if (error != nil) { debuglog(@"failed read file: %@", [error localizeddescription]); } else { if (filedata == nil) { debuglog(@"file info nil"); } } nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *documentsdirectory = [paths objectatindex:0]; nsstring *archivepath = [documentsdirectory stringbyappendingstring:@".zip"]; //zip documents directory ziparchive *archiver = [[ziparchive alloc] init]; [archiver createzipfile2:archivepath]; [archiver addfiletozip:filedatastring newname:@"backup.sqlite"]; [archiver addfiletozip:filedata2string newname:@"backup.sqlite-shm"]; [archiver addfiletozip:filedata3string newname:@"backup.sqlite-wal"]; mfmailcomposeviewcontroller *mailview = [[mfmailcomposeviewcontroller alloc] init]; if (mailview != nil) { mailview.mailcomposedelegate = self; [mailview setsubject:@"database"]; //attach zip file [mailview addattachmentdata:[nsdata datawithcontentsoffile:archivepath] mimetype:@"application/zip" filename:@"test.zip"]; [mailview setmessagebody:@"database attached" ishtml:no]; [self presentviewcontroller:mailview animated:yes completion: null]; }

same behaviour zip file not arrive email

logging archivepath gives me /var/mobile/containers/data/application/1d32a3aa-a431-46234-ae4b-ed944ca2d883f4/documents.zip

typically email attachment doesn't arrive 1 of 2 reasons:

the path used load nsdata resulted in info beingness nil. the file big send via email.

you have several issues leading problem one.

the path zip file in read-only folder - root of app's resource bundle. never utilize nshomedirectory() create paths folders in app's sandbox. things changed in ios 8 , such paths won't work @ all. utilize nssearchpathfordirectoriesindomains proper folder reference such nsdocumentdirectory.

to solve first issue, alter this:

nsstring *archivepath = [documentsdirectory stringbyappendingstring:@".zip"];

to like:

nsstring *archivepath = [documentsdirectory stringbyappendingpathcomponent:@"somefiles.zip"];

it improve store temporary file in caches folder (use nscachesdirectory instead of nsdocumentdirectory). delete file after sending email.

ios cocoa-touch zip

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -