When i share a video using the UIActivityViewController, the twitter post does not show the video. However, if it take the same video and post it using the twitter app, the video shows and plays embedded in the post.
I am using this code:
MyActivityItemProvider * videoItem = [[MyActivityItemProvider alloc] initWithPlaceholderItem:#""];
NSArray * activityItems = [NSArray arrayWithObjects:
videoItem,
nil];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc]
initWithActivityItems:activityItems
applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:nil];
And in MyActivityItemProvider, I have this:
#implementation MyActivityItemProvider
- (MyActivityItemProvider * )initWithPlaceholderItem:(NSString *)placeholderItem
{
self = [super initWithPlaceholderItem:placeholderItem];
return self;
}
- (id)item
{
NSString * path = [[NSBundle mainBundle] pathForResource:#"video_name" ofType:#"mp4"];
NSURL * fileURL = [NSURL fileURLWithPath:path];
return fileURL;
}
#end
Is it possible for a twitter video post to have the video embedded in it (as if I posted it using the twitter app) when posting using the UIActivityViewController?? Any suggestions on how to achieve this (what it looks) rather simple task?
The video is .mp4 and it is 3.1 MB (like I said, appears to post just fine using the Twitter app and I can send the video via txt message fine).
Video cannot be shared with UIActivityViewController.
Thanks to the uploading media new API, you can share video to twitter by it. 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 comment:(NSString*)comment account:(ACAccount*)account withCompletion:(VideoUploadCompletion)completion;
Try this :
+ (void)shareOnTwiiterFromView:(UIViewController *)vc userTitle:(NSString *)title shareURL:(NSString *)urlString
{
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:
SLServiceTypeTwitter];
tweetSheet.completionHandler = ^(SLComposeViewControllerResult result)
{
switch(result)
{
case SLComposeViewControllerResultCancelled:
break;
case SLComposeViewControllerResultDone:
break;
}
};
NSString *twTitle = [NSString stringWithFormat:#"%# %#",title,#"Your App Name"];
[tweetSheet setInitialText:twTitle];
if (![tweetSheet addURL:[NSURL URLWithString:urlString]])
{
NSLog(#"Unable to add the URL!");
}
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
UIPresentationController *control = tweetSheet.presentationController;
[tweetSheet setModalPresentationStyle:UIModalPresentationFormSheet];
[vc presentViewController:control.presentedViewController animated:YES completion:^
{
NSLog(#"Tweet sheet has been presented.");
}];
}
else
{
[vc presentViewController:tweetSheet animated:NO completion:^
{
NSLog(#"Tweet sheet has been presented.");
}];
}
}
else
{
[APP_DEL showErrorAlert:#"No Twitter Account" description:#"There are no twitter accounts configured. You can add or create a Twitter account in Settings."];
}
}
Related
Please Help us..
We want to share projects (i.e. Its Images, text and also my app url).
But i can't get SDK to share all on whatsApp, facebook, twitter, mails and messages. same as android developer using Intent called ACTION_SEND
Try this -
- (void)shareText:(NSString *)text andImage:(UIImage *)image andUrl:(NSURL *)url
{
NSMutableArray *sharingItems = [NSMutableArray new];
if (text) {
[sharingItems addObject:text];
}
if (image) {
[sharingItems addObject:image];
}
if (url) {
[sharingItems addObject:url];
}
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:nil];
[self presentViewController:activityController animated:YES completion:nil];
}
Call shareText like this -
[self shareText:#"Your text" andImage:nil andUrl:nil];
I had an application in which i am sharing a link to twitter using Uiactivityviewcontroller.its just showing the text and link in twitter in my TL.i want it to be shown like as in Facebook with an image extracted from the link.I am doing like this
NSURL *shareUrl = [NSURL URLWithString:#“http://dhdhdh”];
NSString* someText = #“fdfdfd”;
UISimpleTextPrintFormatter *printData = [[UISimpleTextPrintFormatter alloc]
initWithText:#"http://dhdhdh"];
NSArray* dataToShare = #[someText,shareUrl,printData]; // ...or whatever pieces of data you want to share.
NSArray *appActivities = [NSArray arrayWithObjects:[[UrlActivity alloc] init], nil];
UIActivityViewController* activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:dataToShare
applicationActivities:appActivities];
activityViewController.excludedActivityTypes=#[UIActivityTypeAddToReadingList,UIActivityTypeAirDrop,UIActivityTypePrint,UIActivityTypeAssignToContact];
// activityViewController.
[self.navigationController presentViewController:activityViewController animated:YES completion:nil];
Can anybody help me on this?
Try this
go to Build settings in targer-> link Binary with Library - > add "Social" framework
Import #import <Social/Social.h>
NSURL *url = [NSURL URLWithString:#"https://upload.wikimedia.org/wikipedia/en/3/38/Avatarjakeneytiri.jpg"];
UIImage *img = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[controller setInitialText:#"myShare"];
[controller addImage:img];
[self presentViewController:controller animated:YES completion:nil];
}
else {
//wont work in simulator
}
I build an app, when I share photos to Twitter app from my app (by IOS shared-button), it can only display links, I would like to be a display Picture. How can I achieve it?
Try this first you need to import Social framework
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *composeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
if (composeViewController) {
[composeViewController addImage:[UIImage imageNamed:#"Your Image"]];
[composeViewController addURL:[NSURL URLWithString:#"Your URL"]];
NSString *initialTextString = #"Tour Tweet";
[composeViewController setInitialText:initialTextString];
[composeViewController setCompletionHandler:^(SLComposeViewControllerResult result) {
if (result == SLComposeViewControllerResultDone) {
NSLog(#"Posted");
} else if (result == SLComposeViewControllerResultCancelled) {
NSLog(#"Post Cancelled");
} else {
NSLog(#"Post Failed");
}
}];
[self presentViewController:composeViewController animated:YES completion:nil];
}
}
Please go through https://developer.apple.com/library/ios/documentation/NetworkingInternet/Reference/SLComposeViewController_Class/ for more information about SLComposeViewController
Try this you can easily share photo on twitter from your app. and you can also access other options of twitter.
https://github.com/ronaldwang/FHSTwitterEngine
I have seen this format (Image shown below) of share option in most of the iOS applications that support iOS 7.
Is there a default code/framework available to implement this share option as it is shown in the image below?
What you are looking for is the UIActivityViewController.
Since you asked a general question I can't do more than give you a link to the documentation
In addition to the accepted answer, a small piece of example code
- (void)shareText:(NSString *)text andImage:(UIImage *)image andUrl:(NSURL *)url
{
NSMutableArray *sharingItems = [NSMutableArray new];
if (text) {
[sharingItems addObject:text];
}
if (image) {
[sharingItems addObject:image];
}
if (url) {
[sharingItems addObject:url];
}
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:nil];
[self presentViewController:activityController animated:YES completion:nil];
}
Call shareText, leave the things that you don't want to share at nil.
[self shareText:#"Hello world" andImage:nil andUrl:nil];
The Controller in the image you posted is the UIActivitiyViewController this is a link to the class documentation
some good example code:
How to display the default iOS 6 share action sheet with available share options?
I know this question is particular to iOS 7, and the code example specifies iOS 6, but AFAICT they are very similar one might find the example code as helpful as I did.
UIActivityViewController is what you are looking for.
You can specify either the items or the applications
UIActivityViewController *actCont = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
Just use following code for Default Sharing. You can able to add more items into shareItems array as per your requirement.
NSMutableArray *shareItems = [[NSMutableArray alloc] initWithObjects:
#"Hello",
[UIImage imageNamed:#"your_image.png"],
#"http://google.com/", nil];
[self shareItemToOtherApp:shareItems];
Following method is for default sharing Text or Image into other Apps:-
-(void)shareItemToOtherApp:(NSMutableArray *)shareItems{
UIActivityViewController *shareController = [[UIActivityViewController alloc]
initWithActivityItems: shareItems applicationActivities :nil];
[shareController setValue:#"Sharing" forKey:#"subject"];
shareController.excludedActivityTypes = #[UIActivityTypePostToWeibo, UIActivityTypeAssignToContact, UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeSaveToCameraRoll];
shareController.completionHandler = ^(NSString *activityType, BOOL completed)
{
//NSLog(#" activityType: %#", activityType);
//NSLog(#" completed: %i", completed);
};
[self presentViewController: shareController animated: YES completion: nil];
}
If you want to make Custom Sharing sheet then use following code. For this, you have to import <Social/Social.h> framework.
-(void)shareOnFacebook:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
SLComposeViewController *faceSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
// NSLog(#"%#", messageField.text);//This returns the appropriate string
[faceSheet setInitialText:#"Hellooooooo"];
//The facebook VC appears, but initial text is not set to messageField.text
[self presentViewController:faceSheet animated:YES completion:nil];
}
else
{
NSLog(#"Please first install Application and login in Facebook");
}
}
-(void)shareOnTwitter:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:#"Hello"];
[self presentViewController:tweetSheet animated:YES completion:nil];
}
else{
NSLog(#"Please first install Application and login in Twitter");
}
}
Hope, this is what you're looking for. Any concern get back to me. :)
My app let the user take a picture, and add an overlay before saving it.
I'd like to let the user share his picture using whatever app able to handle images (i.e : email, facebook, twitter...), like an Intent on Android.
I tried to use UIDocumentController, but it doesn't show Facebook or Twitter as it does in the official gallery. It also makes my app crashes after taking the second picture.
Is there a simple way to do so ? I don't wan't to use the Facebook SDK and so on.
Here is what I do when the picture is taken :
[stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler:
^(CMSampleBufferRef imageSampleBuffer, NSError *error) {
if(!error){
//Resize the picture and add the overlay
UIImage *picture = [self imageFromSampleBuffer:imageSampleBuffer];
//Custom code letting me save the picture in a specific album
[self.library saveImage:picture toAlbum:#"myApp" metadata:metadata withCompletionBlock:^(NSError *error,NSURL* assetURL) {
if (error!=nil) {
NSLog(#"Big error: %#", [error description]);
} else {
NSLog(#"Image Saved");
NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:#"tmp.jpg"];
//Only way to use UIDocumentController is to save the file at a known location
NSData* imagedata = UIImageJPEGRepresentation(picture, 0.9f);
[imagedata writeToFile:path atomically:NO];
NSLog(#"%#",path);
docController.URL = [NSURL fileURLWithPath:path];
// This make my app crash after the second picture
[docController presentPreviewAnimated:YES];
}
}];
} else {
NSLog(#"%#",error);
}
}];
iOS has an inbuilt social sharing kit. You can share images via Email, Facebook and Twitter. But for using Google+ and other social services you will need their respective SDKs.
1) For Facebook
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:message];
[controller addImage:image];
[self presentViewController:controller animated:YES completion:Nil];
2) For twitter replace SLServiceTypeFacebook with SLServiceTypeTwitter.
3) For Email
MFMailComposeViewController *emailShareController = [[MFMailComposeViewController alloc] init];
emailShareController.mailComposeDelegate = self;
[emailShareController setSubject:#"Share Image"];
[emailShareController setMessageBody:message isHTML:NO];
[emailShareController addAttachmentData:UIImageJPEGRepresentation(image, 1) mimeType:#"image/jpeg" fileName:#"your_image.jpeg"];
if (emailShareController) [self presentViewController:emailShareController animated:YES completion:nil];
4) Remember to add Social.Framework to your project and the following header files
#import <MessageUI/MFMailComposeViewController.h>
#import <Social/Social.h>
#import <MobileCoreServices/MobileCoreServices.h>
5) Set your view controller as delegate of
MFMailComposeViewControllerDelegate
Dismiss MailViewController once mail is send-
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
[self dismissViewControllerAnimated:YES completion:nil];
}