copy video to uipasteboard - iphone

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.

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

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.

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?

Related

IOS - Saved image not showing up on Photos app

I am making an iOS app that saves an image of given URL.
I used the following code.
- (IBAction)save:(id)sender {
UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:photoUrl]]];
NSLog(#"%f,%f",image.size.width,image.size.height);
// Let's save the file into Document folder.
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSLog(#"saving jpg");
NSString *jpegFilePath = [NSString stringWithFormat:#"%#/test.jpg",docDir];
NSData *data2 = [NSData dataWithData:UIImageJPEGRepresentation(image, 1.0f)];//1.0f = 100% quality
[data2 writeToFile:jpegFilePath atomically:YES];
NSLog(#"saving image done");
}
The image is saved successfully after calling this method.
Since I use iPhone simulator, I can see the image is saved my local Library folder.
However, when I open Photos (iPhone navie app) from the simulator, it doesn't detect the image I just saved.
When I save an image from Safari and open Photos app, it detects the image correctly.
But why can't it detect the image I saved thru my ios app? Any solutions?
How come/why do you think or assume any image written to a random location should be known about by the Photos app? That's just nonsense. Use the UIImageWriteToSavedPhotosAlbum() function instead.

Display video properly in IMessage

Currently, I am developing an App in which I have to send photo/video via IMessage. Photo
sending code is proper working but when I am sending video via IMessage I am only getting
a icon make in composer no video is display like below:
I am using this code to display video in IMessage for sending:
if (ver_float < 6.0)
{
UIPasteboard *pasteboard;
pasteboard = [UIPasteboard generalPasteboard];
NSString *filePath =pathToVideo;
NSData *datavideo = [NSData dataWithContentsOfFile:filePath ];
[pasteboard setData:datavideo forPasteboardType:[UIPasteboardTypeListImage objectAtIndex:0]];
}
else
{
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSString *filePath =pathToVideo;
NSData *videoData = [NSData dataWithContentsOfFile:filePath];
[pasteboard setData:videoData forPasteboardType:[UIPasteboardTypeListImage objectAtIndex:0]];
}
NSURL *urlstr = [NSURL URLWithString:#"sms:"];
[[UIApplication sharedApplication] openURL:urlstr];
How can I solve this? Thanx in advance.
Sadly, (as simonbs suggested) the UIPasteboard SDK will not be able to help you with this, it does not support video and audio at this moment. Sadly, I might add.
Possible duplicate :
copy video to uipasteboard

How to post video on twitter in iPhone sdk

I am an ios developer,i am working on app in which i needs to send video on twitter.But i searched and found that we can only post link of Video,but cannot post the video itself in iPhone sdk.
Can anyone suggest me what to do,if i need to post video on twitter.
You can use TWRequest class with
- (void)addMultiPartData:(NSData *)data withName:(NSString *)name type:(NSString *)type
I am not sure if uploading video is possible.
More on using TWRequest https://dev.twitter.com/docs/ios/posting-images-using-twrequest
I just suggest you to look over the TwitVid documentation From bellow link:
http://twitvid.pbworks.com/w/page/22556295/FrontPage
UPDATE:
i use this type of logic in 4.3 with shareKit
NSString *urlstr =[YorURL stringByReplacingOccurrencesOfString:#" " withString:#""];
[urlstr retain];
NSString *apiEndpoint = [NSString stringWithFormat:#"http://tinyurl.com/api-create.php?url=%#",urlstr];
[apiEndpoint retain];
NSLog(#"\n\n APIEndPoint : %#",apiEndpoint);
NSString *shortURL = [NSString stringWithContentsOfURL:[NSURL URLWithString:apiEndpoint]
encoding:NSASCIIStringEncoding
error:nil];
[shortURL retain];
NSLog(#"Long: %# - Short: %#",urlstr,shortURL);
NSString *txtShare=[NSString stringWithFormat:#"You watching Your %#",shortURL];
SHKItem *item = [SHKItem text:txtShare];
[SHK setRootViewController:self];
[SHKTwitter shareItem:item];
hope this help you...
Thanks to the uploading media new API, you can share video to twitter. And I have tried it, it works.
Please check this: https://github.com/liu044100/SocialVideoHelper
You just need to call this class method.
+(void)uploadTwitterVideo:(NSData*)videoData account:(ACAccount*)account withCompletion:(dispatch_block_t)completion;
Hope it can resolve your problem.

Sending Colored Text Messages in iPhone

I am working on iPhone App similar to Pimp My text available here:
http://itunes.apple.com/us/app/pimp-my-text-send-color-text/id489972714?mt=8
I am trying to find a way for sending Colored and animated Messages as the app does.
I have tried this by using UIWebview but it seems the paste board is used in the app to send the iMessage but its not working. The paste board copies the message from editor screen of message and paste it to default iMessage controller. But I am not sure how it is done in the app.
Can anyone suggest any way to send the Colored, animated text with effects?
I have fixed this by following code:
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.persistent = YES;
NSString *imagefile =app.strimagepath;
///
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:imagefile];
if (fileExists)
{
NSData *data = UIImagePNGRepresentation([UIImage imageWithContentsOfFile:imagefile]);
pasteboard.image = [UIImage imageWithData:data];
}
NSString *phoneToCall = #"sms: 123-456-7890";
NSString *phoneToCallEncoded = [phoneToCall stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURL *url = [[NSURL alloc] initWithString:phoneToCallEncoded];
[[UIApplication sharedApplication] openURL:url];
Here app.strimgPath is the path of image stored in document directory. when the MessageView is opened. Longpress and click on Paste and message will be pasted.
May be the question I asked did not clarified correctly as what I want. But the above was something that solved my purpose.

MFMessageComposeViewController not displaying camera icon

When I bring up a "New Message" manually I will see a camera icon to the left of the text edit area. When I use the MFMessageComposeViewController it will not display this icon which means you cannot insert images. I know this can be done because the guys that made txtAgif can do it. One subtle difference is the Caps is turned on. This might be a clue as to how they are getting this to work.
I know that MFMessageComposeViewController does not allow you to insert images programmatically and that is why I'm doing the copy to UIPasteboard trick. This part works perfectly.
This same question has been asked here and here the question has not been answered except for the "It can't be done."
This is my first post so I did not have a high enough ranking to contribute to the other question posts.
How are they doing this? Is there a trick to MFMessageComposeViewController or are they using something completely different?
I have fixed this by following code:
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.persistent = YES;
NSString *imagefile =app.strimagepath;
///
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:imagefile];
if (fileExists)
{
NSData *data = UIImagePNGRepresentation([UIImage imageWithContentsOfFile:imagefile]);
pasteboard.image = [UIImage imageWithData:data];
}
NSString *phoneToCall = #"sms: 123-456-7890";
NSString *phoneToCallEncoded = [phoneToCall stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURL *url = [[NSURL alloc] initWithString:phoneToCallEncoded];
[[UIApplication sharedApplication] openURL:url];
Here app.strimgPath is the path of image stored in document directory. when the MessageView is opened. Longpress and click on Paste and message will be pasted.
I found the answer! Using UIApplication sharedApplication to launch a blank message works while MFMessageComposeViewController does not. Because I'm using the UIPasteboard I do not need to insert items into the body.
NSString *phoneToCall = #"sms: 123-456-7890";
NSString *phoneToCallEncoded = [phoneToCall stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURL *url = [[NSURL alloc] initWithString:phoneToCallEncoded];
[[UIApplication sharedApplication] openURL:url];
This is a bug in MFMessageComposeViewController because why would they allow images to be inserted into one and not the other. I would insert an image but I'm not allowed to because I do not have enough reputation.