Email a file from iphone apps documents folder
I have managed to get in app email working in my app but am having trouble emailing an attachment. I am trying to email the core data .sqlite file. the email sends fine but when i recieve it there is no attachment. I have tried making a copy of the file and emailing that but still no good.
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath = [searchPaths objectAtIndex:0];
NSString *path = [[NSString alloc] initWithFormat:@"%@/data.sqlite",documentPath];
NSString *Newpath = [[NSString alloc] initWithFormat:@"%@/newData.sqlite",documentPath];
NSURL *theFileUrl = [NSURL URLWithString:Newpath];
[[NSFileManager defaultManager] copyItemAtPath:path toPath:Newpath e开发者_StackOverflow社区rror:nil];
NSData *data = [NSData dataWithContentsOfURL: theFileUrl];
NSLog(@"%@",documentPath);
NSLog(@"%@",path);
[controller setSubject:@"Backup"];
[controller addAttachmentData:data mimeType:@"application/x-sqlite3" fileName:@"data.sqlite"];
[controller setMessageBody:@"testing." isHTML:NO];
[self presentModalViewController:controller animated:YES];
[controller release];
Thanks for your help
Use this method dataWithContentsOfFile
: rather than dataWithContentsOfURL
for creating data
. because it may need file:///
protocol service.
Thanks,
精彩评论