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 MFMa开发者_开发百科ilComposeViewController 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
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
精彩评论