2012-02-07 3 views
-1

Можно создать дубликат:
how can send a file as attachment in objective cДобавление изображения в качестве вложения по электронной почте

Я хочу, чтобы добавить изображение в качестве вложения в моем iPhone application.Now Я прилагаю изображение, как это :

NSMutableString * body = [[NSMutableString alloc] initWithString:@"<html><body><img src=\"http://url here\"/>"]; 
[body appendString:@"</body></html>"]; 
[mailer setMessageBody:body isHTML:YES]; 

Но вместо url я хочу включить изображение, которое находится в моей папке ресурсов.

Как я могу сделать то же самое?

+1

дубликат: HTTP: //stackoverflow.com/questions/3049259/iphone-sdk-add-image-to-the-body-of-an-email, http://stackoverflow.com/questions/819021/iphone-how-can-i- embed-images-in-email-from-my-app и http://stackoverflow.com/questions/2534217/display-local-image-in-iphone-html-mail – Raptor

ответ

1

Из документации яблока о MFMailComposeViewController; в основном вы должны запустить UIImage с вашим изображением, извлечь данные изображения (например: если это PNG использовать UIImagePNGRпредставление()) и предоставить правильный тип mime, например. изображение/PNG. Затем используйте указанную функцию ниже (имя файла это имя файла, который вы хотите, чтобы дать вложения, например, «image.png»)

 
addAttachmentData:mimeType:fileName: 
Adds the specified data as an attachment to the message. 

- (void)addAttachmentData:(NSData*)attachment mimeType:(NSString*)mimeType fileName:(NSString*)filename 

Parameters 
attachment 
The data to attach. Typically, this is the contents of a file that you want to include. This parameter must not be nil. 
mimeType 
The MIME type of the specified data. (For example, the MIME type for a JPEG image is image/jpeg.) For a list of valid MIME types, see http://www.iana.org/assignments/media-types/. This parameter must not be nil. 
filename 
The preferred filename to associate with the data. This is the default name applied to the file when it is transferred to its destination. Any path separator (/) characters in the filename are converted to underscore (_) characters prior to transmission. This parameter must not be nil. 
Discussion 
This method attaches the specified data after the message body but before the user’s signature. You may attach multiple files (using different file names) but must do so prior to displaying the mail composition interface. Do not call this method after presenting the interface to the user. 

Пример:


UIImage *myImage = [UIImage imageNamed:@"my_bundled_image"]; 
NSData *myImageData = UIImagePNGRepresentation(myImage); 
[mailComposerViewController addAttachmentData:myImageData mimeType:@"image/png" fileName:"my_image.png"];