如何使用URI方案在邮件中发送附件?企业MDM设备

时间:2021-01-09 18:11:52

I am in a situation where developing App for MDM device in enterprise infra. So, MFMailComposeViewController will not work. How can I send attachment using the URI scheme. Is there any other alternative??

我正处于为企业基础设施开发App for MDM设备的情况。因此,MFMailComposeViewController将无法正常工作。如何使用URI方案发送附件。还有其他选择吗?

1 个解决方案

#1


0  

You need to create mimeType for that

您需要为此创建mimeType

Example:

    MFMailComposeViewController *mc = [[MFMailComposeViewController alloc]init];
    mc.mailComposeDelegate = self;
    NSString *filePath = [[NSBundle mainBundle] pathForResource:filename ofType:extension];
    NSData *fileData = [NSData dataWithContentsOfFile:filePath];
    NSString *mimeType;
    if ([extension isEqualToString:@"jpg"]) {
        mimeType = @"image/jpeg";
    } else if ([extension isEqualToString:@"png"]) {
        mimeType = @"image/png";
    } else if ([extension isEqualToString:@"doc"]) {
        mimeType = @"application/msword";
    } else if ([extension isEqualToString:@"ppt"]) {
        mimeType = @"application/vnd.ms-powerpoint";
    } else if ([extension isEqualToString:@"html"]) {
        mimeType = @"text/html";
    } else if ([extension isEqualToString:@"pdf"]) {
        mimeType = @"application/pdf";
    }
    [mc addAttachmentData:fileData mimeType:mimeType fileName:filename];
    [self presentViewController:mc animated:YES completion:NULL];

#1


0  

You need to create mimeType for that

您需要为此创建mimeType

Example:

    MFMailComposeViewController *mc = [[MFMailComposeViewController alloc]init];
    mc.mailComposeDelegate = self;
    NSString *filePath = [[NSBundle mainBundle] pathForResource:filename ofType:extension];
    NSData *fileData = [NSData dataWithContentsOfFile:filePath];
    NSString *mimeType;
    if ([extension isEqualToString:@"jpg"]) {
        mimeType = @"image/jpeg";
    } else if ([extension isEqualToString:@"png"]) {
        mimeType = @"image/png";
    } else if ([extension isEqualToString:@"doc"]) {
        mimeType = @"application/msword";
    } else if ([extension isEqualToString:@"ppt"]) {
        mimeType = @"application/vnd.ms-powerpoint";
    } else if ([extension isEqualToString:@"html"]) {
        mimeType = @"text/html";
    } else if ([extension isEqualToString:@"pdf"]) {
        mimeType = @"application/pdf";
    }
    [mc addAttachmentData:fileData mimeType:mimeType fileName:filename];
    [self presentViewController:mc animated:YES completion:NULL];