2011-03-09 40 views

回答

1

當您將使用MFMailComposeViewController是總是在郵件的底部顯示的圖像(文字之下,但簽名以上),這不能在該框架的當前版本進行更改。

但是,將圖像數據編碼爲base64並將其直接放置在應用程序的HTML正文中是可能的。我不會在這裏包含代碼(你可以很容易地谷歌它),因爲這是棘手和有問題的,因爲不是所有的讀者都會正確解釋。

如果這是一個所有電子郵件都相同的標題圖片,您可以將其放在某個服務器上,然後在引用此文件的HTML電子郵件正文中包含一個<img>標記。

如果這是一個動態圖像,您可以將您的應用程序上傳到許多圖像託管站點之一,檢索URL並將其作爲標記的src包含在HTML電子郵件正文中。

+0

謝謝,這就是我所做的。 – Vikings 2011-03-11 04:34:33

2
// Action for submenu Email Button 
- (IBAction)emailButtonPressed { 
[delegate playSound:@"Click_16"]; 

if (connectionStatus == YES) 
{ 

    if (maxCounter) 
    { 
     NSString *filename = (NSString *)[self currentImageObject:kSerialKey AtIndex:imageCounter]; 

     NSString* documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 

      // set up image data for email 
     NSString *imageFile = [documentsDirectory stringByAppendingPathComponent:filename]; 
     NSData *imageData = [NSData dataWithContentsOfFile:imageFile]; 

      // set up mail view controller for message 
     MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init]; 
     if (controller != nil) 
     { 
      controller.mailComposeDelegate = self; 
      [controller setSubject:@"Email Subject"]; 
      [controller setMessageBody:@"Check out this picture" isHTML:NO]; 
      [controller addAttachmentData:imageData mimeType:@"image/png" fileName:filename]; 
      [self presentModalViewController:controller animated:YES]; 

     } 

     [controller release]; 

    } 

    else 
     [self genericAlert:@"There are no pictures to email."]; 

} 

else 
    [self genericAlert:@"You are not connected to the internet. Please connect and try again."]; 

} 

// email delegate method to dismiss window 
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error { 
    [self becomeFirstResponder]; 
    [self dismissModalViewControllerAnimated:YES]; 
} 
+0

什麼是代碼中的documentsDirectory? – Vikings 2011-03-09 19:36:05

+0

對不起,我更新了代碼。 documentsDirectory變量是應用程序的文檔目錄:'[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES)objectAtIndex:0];' – FreeAsInBeer 2011-03-09 19:39:56

+0

該代碼仍然會將圖像放置在消息下方並位於簽名之上。 – theChrisKent 2011-03-10 22:01:29

0

您應該使用從MFMailComposeViewController- (void)addAttachmentData:(NSData*)attachment mimeType:(NSString*)mimeType fileName:(NSString*)filename方法。

這是一個great example of this,顯示從相機拍攝圖像,然後發送電子郵件!

+0

我不想將此作爲附件發送,而是在某些文字上方顯示 – Vikings 2011-03-09 19:25:05

+2

您將在電子郵件底部和用戶簽名上方看到圖像。你不能使用這個框架來定製它。 – 2011-03-09 19:29:29

相關問題