Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
- mc.mailComposeDelegate = self;
- [mc setSubject:subject];
- [mc setMessageBody:body isHTML:FALSE];
- if (attachmentData) {
- [mc addAttachmentData:attachmentData mimeType:fileMimeType fileName:fileName];
- }
- if (!recipients || recipients.count == 0) {
- recipients = @[];
- }
- [mc setToRecipients:recipients];
- [presentedViewController presentViewController:mc animated:YES completion:nil];
- - (void)viewDidAppear:(BOOL)animated {
- [super viewDidAppear:animated];
- [self sendSampleMailWithDbAttached];
- }
- - (void)sendSampleMailWithDbAttached {
- MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
- mc.mailComposeDelegate = self;
- [mc setSubject:@"Message Subject"];
- [mc setMessageBody:@"Message Body" isHTML:NO];
- NSString *sqliteFilePath = [self createTestDb];
- NSData *attachmentData = [NSData dataWithContentsOfFile:sqliteFilePath];
- if (attachmentData) {
- [mc addAttachmentData:attachmentData mimeType:@"application/x-sqlite3" fileName:@"xyz.sqlite"];
- }
- [mc setToRecipients:@[@"fake@email.com"]];
- [self presentViewController:mc animated:YES completion:nil];
- }
- - (NSString *)createTestDb {
- NSString *databasePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
- stringByAppendingPathComponent: @"xyz.sqlite"];
- sqlite3 *db;
- if (sqlite3_open([databasePath UTF8String], &db) == SQLITE_OK) {
- NSString *query = @"CREATE TABLE IF NOT EXISTS test(abc TEXT, def TEXT);";
- if (sqlite3_exec(db, [query UTF8String], NULL, NULL, NULL) == SQLITE_OK) {
- query = @"INSERT INTO test(abc, def) VALUES('ABC', '123');";
- }
- sqlite3_close(db);
- }
- return databasePath;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement