簡體   English   中英

從相機發送帶有圖像附件的郵件

[英]Send mail with image attachment from camera

關於如何使用iphone / ipad應用程序發送附件,但附帶了預定義的圖像或其他文件類型,有很多教程和信息。 但是,如何從iPhone / iPad發送帶有當前文件的郵件。 更具體地說,是圖像還是來自相機的圖像?

干杯,謝謝

如果您使用的是UIImagePickerController來捕獲圖像,而不是在捕獲圖像時:

  #import <MobileCoreServices/UTCoreTypes.h> // framework MobileCoreServices.framework

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{    
    NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
    if ([mediaType isEqualToString:(NSString *)kUTTypeImage])
    {
        UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
        [self sendMailWithImage:image];
    }
    [picker dismissModalViewControllerAnimated:NO];
}

- (void)sendMailWithImage:(UIImage *)image
{
     MFMailComposeViewController * mailComposer = [[MFMailComposeViewController alloc]init];
     mailComposer.mailComposeDelegate = self;         
     // make sure you can make NSData from the object
     [mailComposer addAttachmentData:UIImageJPEGRepresentation(image, 1.0) mimeType:@"image/jpg" fileName:@"what ever you want to call the file"];
     [self presentViewController:mailComposer animated:YES completion:nil];
}
MFMailComposeViewController * mailComposer = [[MFMailComposeViewController alloc]init];
mailComposer.mailComposeDelegate = self;
UIImage *myImage = // some code to get your image or what ever file you want
// make sure you can make NSData from the object
[mailComposer addAttachmentData:UIImageJPEGRepresentation(imageToShare, 1.0) mimeType:@"image/jpg" fileName:@"what ever you want to call the file"];
[self presentViewController:mailComposer animated:YES completion:nil];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM