1

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];
ChikabuZ
  • 10,031
  • 5
  • 63
  • 86
Szwedo
  • 354
  • 1
  • 3
  • 15

1 Answers1

3

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];
Dunja Lalic
  • 752
  • 13
  • 26