Vishal
Vishal

Reputation: 8256

copy video to uipasteboard

I have successfully able to copy or add the image to pasteboard by using following code:

if (ver_float < 6.0)
{
    UIPasteboard *pasteboard;
    pasteboard = [UIPasteboard generalPasteboard];
    NSString *filePath =pathToImage;
    [pasteboard setImage:[UIImage imageWithContentsOfFile:filePath]];
}
else
{
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    NSString *filePath =pathToImage;
    NSData *videoData = [NSData dataWithContentsOfFile:filePath];
    [pasteboard setData:videoData forPasteboardType:[UIPasteboardTypeListImage objectAtIndex:0]];

}

NSURL *urlstr = [NSURL URLWithString:@"sms:"];
[[UIApplication sharedApplication] openURL:urlstr];

But the app which I am making is based on both images and videos so that user will be able to send image/video via imessage or messagecomposer. But as I have convert the image into data and added into pasteboard. It is working succesfully and sending through imessage. But I also need to send video via imessage. If anyone has any idea about this please provide me some suggestion or solution.

I would be very thankful for the help.

Upvotes: 8

Views: 2922

Answers (3)

Paulo Alb
Paulo Alb

Reputation: 197

In Swift to copy video to UIPasteboard, assuming you already have a data variable with the movie's binary do :

import UniformTypeIdentifiers 

UIPasteboard.general.setData(data ?? Data(),forPasteboardType: UTType.mpeg4Movie.description)

This worked for me. To test, I copied from the app and then pasted to the iPhone notes app.

Upvotes: 0

Enea G UnlimApps
Enea G UnlimApps

Reputation: 283

NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://pathto.mp4"]];
UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
[pasteBoard setData:data forPasteboardType:@"public.mpeg-4"];

@"public.mpeg-4" from http://www.escape.gr/manuals/qdrop/UTI.html

Upvotes: 9

Murali
Murali

Reputation: 1889

I have also faced the same issue in sending audio file from SMS. But sending video and audio from SMS is not possible with current SDK. You can do this by uploading that video to server and then send that uploaded URL.

How to programmatically send voicemail message on the iPhone?

Upvotes: -1

Related Questions