UIActivityViewController does not show link over facebook when shared - ios

I am not able to see the string and the link when I use share functionality over facebook, below is sample code.
NSArray * activityItems = #[[NSString stringWithFormat:#"Some initial text."], [NSURL URLWithString:#"http://www.google.com"]];
NSArray * applicationActivities = nil;
NSArray * excludeActivities = #[UIActivityTypeAssignToContact, UIActivityTypeCopyToPasteboard, UIActivityTypePostToWeibo, UIActivityTypePrint, UIActivityTypeMessage];
UIActivityViewController * activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities];
activityController.excludedActivityTypes = excludeActivities;
[self presentViewController:activityController animated:YES completion:nil];

You Link Must be a NSURL Object:
NSString *link = #"http://itunes.apple.com/app/id00000000";
NSArray *activityItems = #[ [NSURL URLWithString: link] ];

Your link is there, but it isn't displayed inline as part of the text of your post. Instead it is seen as an attachment-like preview:
If you want to see your link in the text, add it to your NSString activity item:
NSArray * activityItems = #[[NSString stringWithFormat:#"Some initial text. An inline link http://www.yahoo.com"]];
This way you will see the string and the link:

Related

objective-c share image to Instagram from my iOS application

I've spent a long time searching how to share photo from iOS application to Instagram. Other social media like Twitter are working fine. I have found a lot of resources on Google but it's not working.
Please I need some help to add Instagram share button to the UIActivityViewController that already has Twitter share button.
Here is my code:
- (IBAction)shareBtnClicked {
NSString *textToShare = #"Share \r";
NSURL *url = newsC.URL;
NSArray *objectsToShare = #[textToShare, url];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
//this array should add the activities that I don’t want
NSArray *excludeActivities = #[ UIActivityTypePrint,
UIActivityTypeAssignToContact,
UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo
];
activityVC.excludedActivityTypes = excludeActivities;
[self presentViewController:activityVC animated:YES completion:nil];
Thanks in advance
You need to use below method:
-(void)instaPostImage
{
NSURL *myURL = [NSURL URLWithString:#"Your image url"];
NSData * imageData = [[NSData alloc] initWithContentsOfURL:myURL];
UIImage *imgShare = [[UIImage alloc] initWithData:imageData];
NSURL *instagramURL = [NSURL URLWithString:#"instagram://app"];
if([[UIApplication sharedApplication] canOpenURL:instagramURL]) //check for App is install or not
{
UIImage *imageToUse = imgShare;
NSString *documentDirectory=[NSHomeDirectory() stringByAppendingPathComponent:#"Documents"];
NSString *saveImagePath=[documentDirectory stringByAppendingPathComponent:#"Image.png"];
NSData *imageData=UIImagePNGRepresentation(imageToUse);
[imageData writeToFile:saveImagePath atomically:YES];
NSURL *imageURL=[NSURL fileURLWithPath:saveImagePath];
self.documentController=[[UIDocumentInteractionController alloc]init];
self.documentController = [UIDocumentInteractionController interactionControllerWithURL:imageURL];
self.documentController.delegate = self;
self.documentController.annotation = [NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:#"Testing"], #"InstagramCaption", nil];
self.documentController.UTI = #"com.instagram.exclusivegram";
UIViewController *vc = [UIApplication sharedApplication].keyWindow.rootViewController;
[self.documentController presentOpenInMenuFromRect:CGRectMake(1, 1, 1, 1) inView:vc.view animated:YES];
}
else {
DisplayAlertWithTitle(#"Instagram not found", #"")
}
}
Try This
- (IBAction)shareBtnClicked {
NSString *textToShare = #"Share \r";
NSURL *url = newsC.URL;
NSData * imageData = [[NSData alloc] initWithContentsOfURL:url];
UIImage *imgShare = [[UIImage alloc] initWithData:imageData];
NSArray *objectsToShare = #[imgShare, textToShare];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
//this array should add the activities that I don’t want
NSArray *excludeActivities = #[ UIActivityTypePrint,
UIActivityTypeAssignToContact,
UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo
];
activityVC.excludedActivityTypes = excludeActivities;
[self presentViewController:activityVC animated:YES completion:nil];
}

UIActivityViewController social sharing (Facebook) only shows first Object in NSArray

I am trying to share content via Facebook throug the UIActivityViewController and it is working but not showing the correct data.
I am using the following code:
-(void)shareContent{
Item *nItem = [_items getItem:_currentPage];
NSString * urlString = #"http://www.foo.com";
NSString *url1=nItem.img;
NSMutableString *url2 = [[NSMutableString alloc]init];
[url2 appendString:url1];
[url2 appendString:800];
NSURL *url = [NSURL URLWithString:url2];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data];
NSArray * shareItems = #[urlString, img];
UIActivityViewController * avc = [[UIActivityViewController alloc] initWithActivityItems:shareItems applicationActivities:nil];
[self presentViewController:avc animated:YES completion:nil];
}
But is only showing the urlString message, not the image.
Hope you can help with this.
UPDATE - EDIT
Is working fine in Notes, it shows both of them so I think I should something different for Facebook.

Twitter icon not showing on uiactivitycontroller in ios 7

i configured twitter properly in setting menu, my problem is only twitter string is showing on UIActivityViewController, can anyone help me how can i display twitter icon?
NSString *shareString = #"Welcome.";
UIImage *shareImage = [UIImage imageNamed:#"welcome.png"];
NSURL *shareUrl = [NSURL URLWithString:#"http://www.welcome.com"];
NSArray *activityItems = [NSArray arrayWithObjects:shareString, shareImage, shareUrl, nil];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
activityViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
activityViewController.excludedActivityTypes = #[UIActivityTypePostToWeibo, UIActivityTypeAssignToContact];
[self presentViewController:activityViewController animated:YES completion:nil];

ios - UIActivityViewController: SMS option not showing

I am using UIActivityViewController to allow sharing by Mail, Facebook, Twitter and SMS. I have the following code:
-(void) aFunction
{
NSString *textToShare = appRecord.title;
UIImage *imageToShare = [UIImage imageNamed:#"test/png"];
NSURL *url = [NSURL URLWithString:#"http://www.stackoverflow.com"];
NSArray *activityItems = [[NSArray alloc] initWithObjects:textToShare, imageToShare,url,nil];
UIActivity *activity = [[UIActivity alloc] init];
NSArray *applicationActivities = [[NSArray alloc] initWithObjects:activity, nil];
UIActivityViewController *activityVC =
[[UIActivityViewController alloc] initWithActivityItems:activityItems
applicationActivities:applicationActivities];
activityVC.excludedActivityTypes = #[UIActivityTypePostToWeibo, UIActivityTypeAssignToContact, UIActivityTypePrint ,UIActivityTypeCopyToPasteboard,UIActivityTypeAssignToContact,UIActivityTypeSaveToCameraRoll,UIActivityTypeMessage ];
[self presentViewController:activityVC animated:YES completion:nil];
[activityItems release];
[activity release];
[applicationActivities release];
[activity release];
}
The code produces the following:
http://s24.postimg.org/tas3zo9w5/Screen_Shot_2013_10_01_at_5_09_26_PM.png
The SMS option is missing. What I am doing wrong?
you are excluding UIActivityTypeMessage (excludedActivityTypes). This hides the Messages (SMS/iMessage) option

UIActivityViewController sharing image via email has no extension

The image attached is just "Attachment-1", no extension. How do I specify one ?
NSData *compressedImage = UIImageJPEGRepresentation(self.resultImage, 0.8 );
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[ #"Check this out!", compressedImage ] applicationActivities:nil];
[self.navigationController presentViewController:activityViewController animated:YES completion:nil];
According to this answer you should be able to use this workaround to specify a filename
NSData *compressedImage = UIImageJPEGRepresentation(self.resultImage, 0.8 );
NSString *docsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *imagePath = [docsPath stringByAppendingPathComponent:#"image.jpg"];
NSURL *imageUrl = [NSURL fileURLWithPath:imagePath];
[compressedImage writeToURL:imageUrl atomically:YES]; // save the file
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[ #"Check this out!", imageUrl ] applicationActivities:nil];
The obvious drawback of this approach is that you will have to save the image on disk.
Credit to timeuser's suggestion, converting UIImage to NSData.
NSData * data = UIImageJPEGRepresentation(original,1.0);
UIActivityViewController * activity =[[UIActivityViewController alloc] initWithActivityItems:#[#"Your Text", data] applicationActivities:nil];
[self presentViewController:activity animated:true completion:^{ }];

Resources