Attach a video in SKPSMTPMessage

爷,独闯天下 提交于 2019-12-04 05:07:01

问题


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];

回答1:


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];

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];


来源:https://stackoverflow.com/questions/11642087/attach-a-video-in-skpsmtpmessage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!