我有一个应用程序,它使用以下代码创建带有附件的应用程序内邮件:
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];
附件数据是通过哪里创建的
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错误还是上述代码的问题?