I'm writing an iOS app that has locally saved videos (.mov). I'm trying to attach the video via UIActivityViewController. It works great for email. The video is successfully attached and sent. It also works when saving to camera roll.
It doesn't work when attaching to Messages. Only the text is shown. Also Twitter and Facebook do not even show up. When I remove the video attachment, Twitter and Facebook finally begin to show. I don't really care too much about Messages but can anyone tell me why Facebook and Twitter are not showing up?
Heres my code:
- (IBAction) shareVideo {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *URL = [documentsDirectory stringByAppendingPathComponent:demoName];
NSString* someText = demoName;
NSURL *urlToShare = [NSURL fileURLWithPath:URL isDirectory:NO];
NSArray* dataToShare = #[someText, urlToShare];
UIActivityViewController* activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:dataToShare
applicationActivities:nil];
activityViewController.excludedActivityTypes = #[UIActivityTypePrint,UIActivityTypeCopyToPasteboard,UIActivityTypeAssignToContact];
activityViewController.completionHandler = ^(NSString *activityType, BOOL completed) {
//if (completed) {
[self dismissViewControllerAnimated:YES completion:nil];
//}
};
[self presentViewController:activityViewController animated:YES completion:nil];
}
The other answers are outdated. This works:
#IBAction func didTapShare(sender: AnyObject) {
let videoURL = NSURL(fileURLWithPath:localVideoPath)
let activityItems = [videoURL, "Check this out!" ]
let activityController = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)
activityController.popoverPresentationController?.sourceView = self.view
activityController.popoverPresentationController?.sourceRect = self.view.frame
self.presentViewController(activityController, animated: true, completion: nil)
}
You cannot share videos on Facebook, twitter or on sms in iOS 6 or below. It's only available in iOS7.
Also, please check https://stackoverflow.com/a/20211603/2074320 for your information.
they are hidden because you cannot display movs on fb twitter or in sms
Related
Im using UIActivityViewController for share image to social network. I need to post my image to friend's wall. Is it possible to post image to friend's wall using UIActivityViewController.
With NSData, you can add image to UIActivityViewController. Try below one.
NSString *text = #"your text goes here";
NSData *Da = UIImageJPEGRepresentation([UIImage imageNamed:#"Icon.png"], 1.0);
NSArray * activityItems = #[text,Da];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:[NSArray arrayWithObjects:nil]];
activityVC.excludedActivityTypes = #[UIActivityTypePostToWeibo]; //or whichever you don't need
[activityVC setCompletionHandler:^(NSString *activityType, BOOL completed) {
}];
[self presentViewController:activityVC animated:YES completion:nil];
In my App I sharing an image on Instagram. It is working well in my app.
I am using the following code.
#property (nonatomic, retain) UIDocumentInteractionController *dic;
CGRect rect = CGRectMake(0 ,0 , 0, 0);
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIGraphicsEndImageContext();
NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:#"Documents/test.igo"];
NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:#"file://%#", jpgPath]];
// NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:#"file://%#", screenshot]];
self.dic.UTI = #"com.instagram.photo";
self.dic = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
self.dic=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
[self.dic presentOpenInMenuFromRect: rect inView: self.view animated: YES ];
- (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate {
UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL: fileURL];
interactionController.delegate = interactionDelegate;
return interactionController;
}
Now I also want to share some text with the image.
As shown in the Image below. In " Write a Caption", I want some default custom text for eg. "Share this photo".
How can I do this?
Thanks in advance...
Edited
I am opening Instagram from my app for sharing images and it works fine.
But Is it possible that Can I check Whether the user has shared it successfully or not?
Means I want to perform some action in my DB when user successfully shares an image.
How can i do this?
I got my answer. Just added a line and it worked for me.
self.dic.annotation = [NSDictionary dictionaryWithObject:#"Here Give what you want to share" forKey:#"InstagramCaption"];
Thanks...
It is also documented in the official documentation at http://instagram.com/developer/iphone-hooks/
To include a pre-filled caption with your photo, you can set the annotation property on the document interaction request to an NSDictionary containing an NSString under the key "InstagramCaption". Note: this feature will be available on Instagram 2.1 and later.
You are no more allowed to share Pre-Filled Text with Instagram or Facebook.
Only Images/Screenshots can be shared via UIDocumentInteractionController.
I am integrating Instagram into my application using the instagram-ios-sdk. I can successfully login to Instagram and obtain an access token, but after that when I am try to post a picture using UIDocumentInteractionController from UIImagePickerController, the image is not posting. The code to send a picture is given below:
(void)_startUpload:(UIImage *) image {
NSLog(#"Image Object = %#",NSStringFromCGSize(image.size));
NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:#"Documents/Test.igo"];
[UIImageJPEGRepresentation(image, 1.0) writeToFile:jpgPath atomically:YES];
NSLog(#"file url %#",jpgPath);
NSURL *igImageHookFile = [[NSURL alloc] init];
igImageHookFile = [NSURL fileURLWithPath:jpgPath];
NSLog(#"File Url = %#",igImageHookFile);
documentInteractionController.UTI = #"com.instagram.photo";
[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
[self setupControllerWithURL:igImageHookFile usingDelegate:self];
[documentInteractionController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
}
(UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate {
NSLog(#"%#",fileURL);
UIDocumentInteractionController *interactionController =
[UIDocumentInteractionController interactionControllerWithURL: fileURL];
interactionController.delegate = interactionDelegate;
return interactionController;
}
I converted the image to .ig format, with a resolution of (612 *612). But still the image is not posting on Instagram. Am I missing something? Can any one help me with this?
Thanks
First off, in your code, you're not assigning the return value of setupControllerWithURL: usingDelegate: to an object, so that method isn't actually accomplishing anything, just creating a new instance of UIDocumentInteractionController and discarding it.
Secondly, from the documentation:
"Note that the caller of this method needs to retain the returned object."
You're not retaining the document controller (or assigning it to a strongly referenced property in the case of ARC) from what I can tell.
Try this -
In your #interface:
#property (nonatomic, strong) UIDocumentInteractionController *documentController;
In your #implementation:
self.documentController = [UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
self.documentController.delegate = self;
self.documentController.UTI = #"com.instagram.photo";
[self.documentController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
Also, the line NSURL *igImageHookFile = [[NSURL alloc] init]; is unnecessary because in the next line igImageHookFile = [NSURL fileURLWithPath:jpgPath]; you're creating a new instance and discarding the first one. Just use NSURL *igImageHookFile = [NSURL fileURLWithPath:jpgPath];
I want to trim video so i am using UIVideoEditorController but when i check can edit file then it return false for all the files, mp4,mov,m4v. So any one will please guide me what is the problem.
Will you please give me the link of any tutorial of using UIVIdeoEditorcontroller
UIVideoEditorController does not work on simulator so it always returns false, it will work fine on device.
You can find editing of video by path through UIVideoEditorController.
UIVideoEditorController* videoEditor = [[UIVideoEditorController alloc] init];
videoEditor.delegate=self;
NSString* videoPath = [[NSBundle mainBundle] pathForResource:#"video" ofType:#"MOV"];
if ( [UIVideoEditorController canEditVideoAtPath:videoPath] )
{
videoEditor.videoPath = videoPath;
videoEditor.videoMaximumDuration = 10.0;
//[self.customAvPlayerView addSubview:videoEditor.view];
[self presentViewController:videoEditor animated:YES completion:nil];
}
else
{
NSLog( #"can't edit video at %#", videoPath );
}
http://www.raywenderlich.com/forums/viewtopic.php?t=11571&p=60182
I want to send message with image data. So I used MFMessageComposeViewController.
But that controller provide only SMS service. So I used UIPasteBoard attached an image data.
But It doesn't work, either. There are no "Paste" button created when typing messages. Attaching image at UIPasteBoard was clearly success.
I think using MFMessageComposeViewController doesn't solve my problem.
How can I accomplish my goal?
This is not possible with the current MessageUI API: the MSMessageComposeViewController doesn't accept attachments like the MFMailComposeViewController does.
The only way to do this currently is to use an external service that allows you to send mms via a REST call for example.
GSMA defines a REST specification for exactly this purpose:
http://www.gsmworld.com/oneapi/reference_documentation-version_1.html (multiple pdf's on this page)
Try to find a local service provider that implements this specification and you're good to go.
Just to add the direct wiki link to the OneAPI MMS spec: http://gsma.securespsite.com/access/Access%20API%20Wiki/MMS%20RESTful%20API.aspx and a link to the PHP/Java sandbox https://github.com/OneAPI/GSMA-OneAPI where MMS can be tested locally . Cheers.
Here is the correct working code and it is working perfectly on my device.
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.persistent = NO;
NSMutableDictionary *text = [NSMutableDictionary dictionaryWithCapacity:1];
[text setValue:label.text forKey:(NSString *)kUTTypeUTF8PlainText];
NSMutableDictionary *image = [NSMutableDictionary dictionaryWithCapacity:1];
[image setValue:imageView.image forKey:(NSString *)kUTTypePNG];
pasteboard.items = [NSArray arrayWithObjects:image,text, nil];
NSString *phoneToCall = #"sms:";
NSString *phoneToCallEncoded = [phoneToCall stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURL *url = [[NSURL alloc] initWithString:phoneToCallEncoded];
[[UIApplication sharedApplication] openURL:url];
I had the same question that I posted here. There is a bug in MFMessageComposeViewController and if you just use the code below it will launch a message that you can insert images into
NSString *phoneToCall = #"sms: 123-456-7890";
NSString *phoneToCallEncoded = [phoneToCall stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURL *url = [[NSURL alloc] initWithString:phoneToCallEncoded];
[[UIApplication sharedApplication] openURL:url];
This Method is tested and verified. I Used it in my code.
if (![MFMessageComposeViewController canSendText]) {
UIAlertView *alertV = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Your device not support SMS \nOr you hadn't login your iMessage" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[alertV show];
return;
}
MFMessageComposeViewController *mVC = [[MFMessageComposeViewController alloc] init];
mVC.body = #"jjjj";
mVC.recipients = #[#"00XXXXXXXXXX"];
mVC.messageComposeDelegate = self;
if ([MFMessageComposeViewController canSendAttachments]) {
NSLog(#"ok");
}
[mVC addAttachmentData: UIImageJPEGRepresentation([UIImage imageNamed:#"test.jpg"], 1.0) typeIdentifier:#"public.data" filename:#"image.jpeg"];
[self presentViewController:mVC animated:YES completion:nil];
You can use any jpeg jpg and png formats.
Swift way. Works in iOS11
func shareViaMessage() {
if !MFMessageComposeViewController.canSendText() {
showAlert("Text services are not available")
return
}
let textComposer = MFMessageComposeViewController()
textComposer.messageComposeDelegate = self
textComposer.body = "Try my #app"
if MFMessageComposeViewController.canSendSubject() {
textComposer.subject = "AppName"
}
if MFMessageComposeViewController.canSendAttachments() {
let imageData = UIImageJPEGRepresentation(imageView.image!, 1.0)
textComposer.addAttachmentData(imageData!, typeIdentifier: "image/jpg", filename: "photo.jpg")
}
present(textComposer, animated: true)
}
Why don't you share the Image and Text via the Share API (selecting Message, and if you want exluding Facebook, twitter etc..)