在SKPSMTPMessage中附加视频 [英] Attach a video in SKPSMTPMessage
问题描述
我的应用程序中有一个VideoClip.mp4存储在我的文档目录中。我可以使用SKPSMTPMessage(电子邮件,主题,正文等)成功发送电子邮件,但我无法附加视频。我已经搜索了很多,但我会继续寻找。如果有人能帮助我,那将是非常感激的。谢谢!
I have a VideoClip.mp4 stored in my documents directory in my app. I can successfully send an email with SKPSMTPMessage, (email, subject, body, ect.) but I am having trouble attaching the video. I have already searched around a lot, but I will keep looking. If anyone can help me, that would be appreciated very much. Thank you!
这段代码(显然)附加了一个图像,但是我无法弄清楚如何操纵它来附加视频:
This code (apparently) attaches an image, but I haven't been able to figure out how to manipulate it to attach a video:
NSString *image_path = [[NSBundle mainBundle] pathForResource:@\"Success\" ofType:@\"png\"];
NSData *image_data = [NSData dataWithContentsOfFile:image_path];
NSDictionary *image_part = [NSDictionary dictionaryWithObjectsAndKeys:
@\"inline;\r\n\tfilename=\\"Success.png\\"\",kSKPSMTPPartContentDispositionKey,
@\"base64\",kSKPSMTPPartContentTransferEncodingKey,
@\"image/png;\r\n\tname=Success.png;\r\n\tx-unix-mode=0666\",kSKPSMTPPartContentTypeKey,
[image_data encodeWrappedBase64ForData],kSKPSMTPPartMessageKey,
nil];
推荐答案
这是一个迟到的答案,但希望它有助于某人。假设您从文档目录( videoPath
)中知道您的视频文件的路径,请执行以下代码:
It's a late answer, but hope it helps someone. Assuming you know a path to your video file from documents directory (videoPath
), here's the code:
NSData *videoData = [NSData dataWithContentsOfFile: videoPath];
NSDictionary *videoPart = [NSDictionary dictionaryWithObjectsAndKeys:@"video/quicktime;\r\n\tx-unix-mode=0644;\r\n\tname=\"video.mov\"",kSKPSMTPPartContentTypeKey,
@"attachment;\r\n\tfilename=\"video.mov\"",kSKPSMTPPartContentDispositionKey,[videoData encodeBase64ForData],kSKPSMTPPartMessageKey,@"base64",kSKPSMTPPartContentTransferEncodingKey,nil];
然后,您可以将其附加到 SKPSMTPMessage * testMsg
这样的对象(假设你有其余的 testMsg
必需的属性设置,如凭证等):
Then you can attach it to a SKPSMTPMessage *testMsg
object like this (assuming you have the rest of testMsg
required properties set, like credentials etc):
testMsg.parts = [NSArray arrayWithObjects: videoPart,nil];
这篇关于在SKPSMTPMessage中附加视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!