2012-07-25 69 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];