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.
Related
I am using UIActivityViewController for sending an sms with image, URL and a text. But SMS is showing full url including all parameters, instead of a clickable short link.
NSURL *urlImage = [NSURL URLWithString:[NSString stringWithFormat:#"%#",imageUrl]];
NSData *data = [NSData dataWithContentsOfURL:urlImage];
UIImage *img = [[UIImage alloc] initWithData:data];
NSURL *url = [NSURL URLWithString:shareURl];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:#[#"I just won this on test. Check it out!", url, img] applicationActivities:nil];
activityVC.excludedActivityTypes = #[UIActivityTypeSaveToCameraRoll, UIActivityTypePostToFacebook, UIActivityTypePostToTwitter];
[self presentViewController:activityVC animated:YES completion:nil];
What I am getting is:
+
What I need is:
Is there any way we can achieve this?
I want to share some text on Instagram either on feed or direct message from my app in iOS. Can anybody let me know How to do that? I've tried the Instagram API Doc but using this Caption is not working the only Image is sharing in feed or story. But in Android, it is sharing text as a direct message using intent.
I've tried the following code:
#property(nonatomic, strong) UIDocumentInteractionController *docController;
-(void)InstagramBtnClick: (id)sender {
NSURL *myImgUrl = [NSURL URLWithString: #"https://www.materials-world.com/bricks/glen-gery/red/images/red_cliff_w12-DA.jpg"];
NSData * imageData = [[NSData alloc] initWithContentsOfURL: myImgUrl];
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.igo"];
NSData *imageData=UIImagePNGRepresentation(imageToUse);
[imageData writeToFile:saveImagePath atomically:YES];
NSURL *imageURL=[NSURL fileURLWithPath:saveImagePath];
self.docController=[[UIDocumentInteractionController alloc]init];
self.docController = [UIDocumentInteractionController interactionControllerWithURL:imageURL];
self.docController.delegate = self;
self.docController.annotation = [NSDictionary dictionaryWithObjectsAndKeys:#"Testing Caption Text", #"InstagramCaption", nil];
self.docController.UTI = #"com.instagram.exclusivegram";
UIViewController *vc = [self topMostController];
[self.docController presentOpenInMenuFromRect:CGRectMake(1, 1, 1, 1) inView:vc.view animated:YES];
}
else {
NSLog(#"Instagram App not Found");
}
}
Is there any other option so that the text can be added in the sharing content in iOS.
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];
}
I'm using the UIActivityViewController to share some text, a URL, and an image to email, Twitter, Facebook, etc.
// Define parameters
NSString *text = #"example text";
NSURL *url = [NSURL URLWithString:#"www.google.com"];
UIImage *image = self.myImage;
// Create and display activity view controller
NSArray *activityItems = #[text, url, image];
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityController animated:YES completion:nil];
The text and image appear in the email and get posted to Twitter/Facebook, but the URL doesn't show up anywhere. Any ideas what the problem could be?
NSURL *url = [NSURL URLWithString:#"www.google.com"];
Is not a valid URL. It does not have a scheme. Try:
NSURL *url = [NSURL URLWithString:#"http://www.google.com"];
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:^{ }];