IOS Custom Icon Email Attachment

I registered my own CFBundleDocumentTypes file type as described in this link: How to register a custom file type in iOS

Everything works fine, except when I send mail through the MFMailComposeViewController, this simple default application icon still remains, not my own. When I receive mail, my own icon is displayed. Can I change the default MFMailComposeViewController icon when sending mail?

Thanks for your help, Martin.

+6
source share
1 answer

When you add an attachment, do you set the mime type correctly for your custom file type? Perhaps you need to explicitly convert the UTI to a MIME type, and then specify that when using the MFMailComposeViewController method:

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

Convert 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; 

Be sure to add and import the following frameworks:

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

Code Snippet Source: Damien DeVille

+1
source

Source: https://habr.com/ru/post/891116/


All Articles