Ios7 MFMailComposeViewController的addAttachmentData在iOS 7下是否已损坏?
我有一个应用程序,它使用以下代码创建带附件的应用内邮件:Ios7 MFMailComposeViewController的addAttachmentData在iOS 7下是否已损坏?,ios7,Ios7,我有一个应用程序,它使用以下代码创建带附件的应用内邮件: MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init]; [controller setMailComposeDelegate:self]; [controller setToRecipients:recipient != nil ? [NSArray arrayWithObject:recipient] : nil]; [c
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
[controller setMailComposeDelegate:self];
[controller setToRecipients:recipient != nil ? [NSArray arrayWithObject:recipient] : nil];
[controller setSubject:subject];
[controller setMessageBody:body isHTML:isHTML];
[controller addAttachmentData:attachmentData mimeType:attachmentType fileName:attachmentFileName];
其中通过创建attachmentData
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
// build the file name using the documents directory:
NSString *fileName = [NSString stringWithFormat:@"%@/%@", documentsDirectory, attachmentFileName];
NSData *attachmentData = [NSData dataWithContentsOfFile:fileName];
mime类型是通过
/*
* Infer the mime type
*/
NSString* attachmentMimeType = nil;
@try {
NSString* fullPath = [fileName stringByExpandingTildeInPath];
NSURL* fileUrl = [NSURL fileURLWithPath:fullPath];
NSURLRequest* fileUrlRequest = [NSURLRequest requestWithURL:fileUrl];
NSError* error = nil;
NSURLResponse* response = nil;
[NSURLConnection sendSynchronousRequest:fileUrlRequest returningResponse:&response error:&error];
attachmentMimeType = [response MIMEType];
}
@catch (NSException * e) {
// Test
}
@finally {
}
/*
* Default mime type is application/octet-stream
*/
if(attachmentMimeType == nil) attachmentMimeType = @"application/octet-stream";
该代码在iOS 4、iOS 5、iOS 6下正常工作。但是,在iOS 7.0下,附件丢失。这是一个iOS错误还是上述代码的问题?您使用什么“mimetype”?“…mime类型“application/octet stream”在ios 7设备上不工作。它完全忽略附件。”在我的测试用例中,mime类型是text/html。我使用“代码”来推断正确的mime类型。我将更新我的问题。谢谢Vegar。行为确实取决于mime类型:application/zip工作。“text/html”不起作用。