iSagar
iSagar

Reputation: 107

MFMailComposeViewController configure mimetype for attachment

I need some help. I am trying to attach files to mail using, [mail addAttachmentData:attachmentData mimeType:@"image/png" fileName:fileName]; but the problem is that if i need to send a .jpeg image i need to repeat code just for setting mime type to "mimeType:@"image/jpeg". My question is that is there any general mimeType that can attach any kind of file irrespective of .doc,.ppt,.pdf or an audio or video file. is there any general mimeType: for an kind of attachment.

Thanks in advance.

Upvotes: 1

Views: 2565

Answers (3)

Maybe you could use @"application/octet-stream", which means something like “Binary data file”

Upvotes: 1

Prasad.Jakka
Prasad.Jakka

Reputation: 159

NSURL * fileURL1 = [[NSURL alloc] initFileURLWithPath:videoStr];
NSData *videofile = [[NSData alloc] initWithContentsOfURL:fileURL1];
[picker addAttachmentData:videofile mimeType:@"video/quicktime" fileName:@"Video.mov"];

It will work fine for attaching video file in mfmai

Upvotes: 0

Michael Kessler
Michael Kessler

Reputation: 14235

Possible solution (taken from here):

NSString* fileMIMEType(NSString * file) {
    CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (CFStringRef)[file pathExtension], NULL);
    CFStringRef MIMEType = UTTypeCopyPreferredTagWithClass (UTI, kUTTagClassMIMEType);
    CFRelease(UTI);
    return [(NSString *)MIMEType autorelease];
}

You need to include the MobileCoreServices framework, and add:

#import <MobileCoreServices/MobileCoreServices.h>

Another possible solution is an open source project MagicKit.

Upvotes: 1

Related Questions