【发布时间】:2018-06-05 19:38:25
【问题描述】:
我正在尝试将视频附加到电子邮件中。它不是本地视频,所以我将其写入文件。然后我从该文件中获取数据并附加到电子邮件中。当电子邮件出现时,唯一的文件名是“video.mp4”,没有视频。
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
NSData *videoData = [NSData dataWithContentsOfURL:url];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *tempPath = [documentsDirectory stringByAppendingFormat:@"/video.mp4"];
NSLog(@"writing");
BOOL success = [videoData writeToFile:tempPath atomically:NO];
if (success){
NSError *error = nil;
NSData *data = [NSData dataWithContentsOfFile:tempPath];
NSLog(@"path: %@", tempPath);
if (error) {
NSLog(@"%@", [error localizedDescription]);
}else{
[controller addAttachmentData:data mimeType:@"video/mp4" fileName:@"video.mp4"];
NSLog(@"Data has loaded successfully.");
}
}
【问题讨论】:
-
确定不成功?以我的经验,这就是视频附件的所有
MFMailComposeViewController节目。您是否查看过您收到的电子邮件是否附有 MP4? -
@Linuxios 你是对的,它确实发送了。你知道是否有办法在电子邮件中显示视频吗?如果电子邮件中只写“video.mp4”,我不确定用户是否会理解视频已附加。
标签: ios objective-c nsdata mfmailcomposeviewcontroller