【问题标题】:Attach a video in SKPSMTPMessage在 SKPSMTPMessage 中附加视频
【发布时间】:2012-07-23 10:24:12
【问题描述】:

我有一个 VideoClip.mp4 存储在我的应用程序的文档目录中。我可以使用 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];

【问题讨论】:

    标签: ios xcode email nsdocumentdirectory skpsmtpmessage


    【解决方案1】:

    这是一个迟到的答案,但希望它对某人有所帮助。假设您知道文档目录 (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];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-18
      • 2019-10-07
      • 1970-01-01
      • 1970-01-01
      • 2018-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多