2012-07-25 70 views
1

我的应用程序中有一个VideoClip.mp4存储在我的文档目录中。我可以使用SKPSMTPMessage(电子邮件,主题,正文等)成功发送电子邮件,但我在附加视频时遇到问题。我已经搜寻了很多,但我会继续寻找。如果有人能帮助我,那将非常感激。谢谢!在SKPSMTPMessage中附加视频

此代码(显然)附加的图像,但我一直无法弄清楚如何操纵它附加了视频:

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

回答

3

这是一个迟到的回答,但希望它可以帮助别人。假设你知道从文件目录(videoPath)视频文件的路径,下面的代码:

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需要的属性,其余设置,像凭证等):

testMsg.parts = [NSArray arrayWithObjects: videoPart,nil];