0
votes

I am downloading image from UIWebView with this method

NSURL *imgUrl=[[NSURL alloc] initWithString:[[DataPassing sharedManager] pageIMGurl]];
    NSData *imgData = [NSData dataWithContentsOfURL:imgUrl];
UIImage *img = [UIImage imageWithData:imgData];

now I want to send this downloaded or saved or data Image with email using MFMailComposeViewController

NSData *imageData = UIImagePNGRepresentation(image);
        [mailer addAttachmentData:img mimeType:@"image/png" fileName:@"mobiletutsImage"];

Now issue comes that I don't know the type of downloaded image in 'img', so i can put rite mimeType:@"image/png". What if the downloaded image is jpeg?

how to store multiple mimetypes and check with "img" and then send.

1

1 Answers

1
votes

There is no need to worry about the image type. UIImagePNGRepresentation returns the png representation of the UIImage object.

If you use UIImageJPEGRepresentation method to convert your UIImage into NSData, you should pass @"image/jpg" as mime type.

One more way is in the url, the last component will be image name. Fetch the extension of it and you will come to know the mime type.