Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS Custom Icon Email Attachment

I registered my own custom CFBundleDocumentTypes filetype as described in this link: How do I register a custom filetype in iOS

Everything is working fine except when I send a mail via MFMailComposeViewController there is still this plain default attachment icon instead of my own. When I receive the mail my own icon is displayed. Is it possible to change the default MFMailComposeViewController-attachment icon when sending the mail?

Thanks for your help, Martin

like image 895
Martin Kapfhammer Avatar asked Jun 22 '11 13:06

Martin Kapfhammer


People also ask

How do I attach a jpeg to an email on my iPhone?

Attach a photo, video, or document to an emailabove the keyboard, then locate the document in Files. In Files, tap Browse or Recent at the bottom of the screen, then tap a file, location, or folder to open it. above the keyboard, then choose a photo or video.

How do I mark up an attachment on my iPhone?

Tap the attachment, then tap the gray arrow icon . Tap the Markup button to add your markup. Tap the plus button to add a signature, text, and more. Tap Done, then send your email.


1 Answers

When you add the attachment are you specifying the mime type correctly for your custom filetype? Perhaps you need to explicitly convert your UTI to a MIME type and then specify that when using the MFMailComposeViewController method:

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

Converting UTI to MIME type

NSString *filePath = ... // file path for your file of a custom type.
CFStringRef fileExtension = (__bridge CFStringRef)[filePath pathExtension];
CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, fileExtension, NULL);
CFStringRef MIMEType = UTTypeCopyPreferredTagWithClass(UTI, kUTTagClassMIMEType);
CFRelease(UTI);
NSString *MIMETypeString = (__bridge_transfer NSString *)MIMEType;

Make sure to add and import the following frameworks:

#import <MobileCoreServices/MobileCoreServices.h>
#import <CoreServices/CoreServices.h>

Code snippet source: Damien DeVille

like image 78
brynbodayle Avatar answered Sep 28 '22 03:09

brynbodayle