2011-08-08 66 views
1

我想補充的.jpg這樣:如何將gif添加到iPhone郵件的附件中?

UIImage *sentPic = self.image; 
NSData *imageData = UIImageJPEGRepresentation(sentPic, 1); 
[picker addAttachmentData:imageData mimeType:@"image/jpg" fileName:@"pic.jpg"]; 

我把它改爲「圖像/ GIF」。但它不能正常工作。 Th Gif只是郵件中的靜態圖片。

回答

1
NSData *imageData = [[NSData alloc] initWithContentsOfFile:pathToGifFile]; 
[picker addAttachmentData:imageData mimeType:@"image/gif" fileName:@"pic.gif"]; 
[imageData release]; 

這將添加它作爲附件,但我不知道如果這就是你想要的,或者你想在消息內顯示圖像?

+0

謝謝。這也適用:NSData * imageDataGif = [NSData dataWithContentsOfFile:[NSString stringWithFormat:@「%@/Documents/gif.gif」,NSHomeDirectory()]]; [picker addAttachmentData:imageDataGif mimeType:@「image/GIF」fileName:@「GifDemo.gif」]; –

1

你有沒有試過HTML代碼在您的電子郵件這樣的:

NSString *emailBody = @"It is a gif email!"; 
emailBody = [EmailBody stringByAppendingString:@"<img src='http://xx.xx.pic.gif'>"]; 
[picker setMessageBody:emailBody isHTML:YES]; 

我沒有測試過的代碼,你可以試試。告訴我們它是否有效。

0

我剛測試過這個。很棒的作品:

NSString *pathForGif = [[NSBundle mainBundle] pathForResource: @"<your file name>" ofType: @"gif"]; 

NSData *gifData = [NSData dataWithContentsOfFile: pathForGif]; 

[mailController addAttachmentData:gifData mimeType:@"image/gif" fileName:@"EmailGIF.gif"]; 
[self presentModalViewController:mailController animated:YES]; 
相關問題