SHARE
TWEET

Untitled

a guest Jun 20th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
  2. mc.mailComposeDelegate = self;
  3. [mc setSubject:subject];
  4. [mc setMessageBody:body isHTML:FALSE];
  5. if (attachmentData) {
  6.  [mc addAttachmentData:attachmentData mimeType:fileMimeType fileName:fileName];
  7. }
  8. if (!recipients || recipients.count == 0) {
  9.  recipients = @[];
  10. }
  11. [mc setToRecipients:recipients];
  12. [presentedViewController presentViewController:mc animated:YES completion:nil];
  13.      
  14. - (void)viewDidAppear:(BOOL)animated {
  15.     [super viewDidAppear:animated];
  16.     [self sendSampleMailWithDbAttached];
  17. }
  18.  
  19. - (void)sendSampleMailWithDbAttached {
  20.     MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
  21.     mc.mailComposeDelegate = self;
  22.     [mc setSubject:@"Message Subject"];
  23.     [mc setMessageBody:@"Message Body" isHTML:NO];
  24.     NSString *sqliteFilePath = [self createTestDb];
  25.     NSData *attachmentData = [NSData dataWithContentsOfFile:sqliteFilePath];
  26.     if (attachmentData) {
  27.         [mc addAttachmentData:attachmentData mimeType:@"application/x-sqlite3" fileName:@"xyz.sqlite"];
  28.     }
  29.     [mc setToRecipients:@[@"fake@email.com"]];
  30.     [self presentViewController:mc animated:YES completion:nil];
  31. }
  32.  
  33. - (NSString *)createTestDb {
  34.     NSString *databasePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
  35.                               stringByAppendingPathComponent: @"xyz.sqlite"];
  36.     sqlite3 *db;
  37.     if (sqlite3_open([databasePath UTF8String], &db) == SQLITE_OK) {
  38.         NSString *query = @"CREATE TABLE IF NOT EXISTS test(abc TEXT, def TEXT);";
  39.         if (sqlite3_exec(db, [query UTF8String], NULL, NULL, NULL) == SQLITE_OK) {
  40.             query = @"INSERT INTO test(abc, def) VALUES('ABC', '123');";
  41.         }
  42.         sqlite3_close(db);
  43.     }
  44.     return databasePath;
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top