Share multiple photos on the same post in Facebook using UIActivityViewController - ios

Below given code, I'm sharing 1 text and 2 photos using UIActivityViewController. Then I choose Facebook for my sharing destination and it's shared on 2 separated posts on the feed for each photo but what I want is to share it in one single post with 1 text and 2 photos. How can I achieve this? I have done lot of search on here and found no proper answer. It seems to me that Facebook may have no clear way to do this, so it's like such an issue may lie on their side.
activityItems = #[self.textDetail.text, self.imageFileView1.image, self.imageFileView2.image];
UIActivityViewController *activityController =
[[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];

The issue was solved by either new iOS ver or Facebook's new way of handling activity items. Anyway it works as I expect now.

Try this:
NSString *message = #"msg To post";
NSMutableArray *postsImages=[[NSMutableArray alloc] init];
[postsImages addObject:message];
for (UIImage *img in collectionImageArray) {
[postsImages addObject:img];
}
UIActivityViewController *activityVC = [[UIActivityViewController alloc]
initWithActivityItems:postsImages
applicationActivities:nil];
[activityVC setCompletionWithItemsHandler:^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
if([activityType isEqualToString:UIActivityTypePostToTwitter]){
//twitter selected
}
}];
[self presentViewController:activityVC animated:YES completion:nil];

Related

How to pass API and fetched data to UIActivityViewCollector

I am using a table view and i am using it to display clips which i am fetching from core data. Now i have an API for clip path which will connect it to the server clips i want to pass clip id with that API and pass the clip name fetched from the core data.i have tried following thing to make it work but gives me error.I think i am doing it wrong. How would i do that.
//here is my code but it is giving me error. Can't pass it this way.
NSArray * activityItems = #[[NSURL URLWithString:#"http://example.com/view-videos.html?task=clip.details&id=%#",_fetchid]]; // this is giving me error and here i also want to send selected clip name with this API
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:videoToShare applicationActivities:nil];
activityVC.excludedActivityTypes = #[UIActivityTypePostToFacebook,UIActivityTypePostToTwitter,UIActivityTypePostToWeibo,UIActivityTypeCopyToPasteboard,UIActivityTypeMessage];
[self presentViewController:activityVC animated:YES completion:nil];
}
Try something like this. You are passing some other object not activityItems.
NSString *urlString = [NSString stringWithFormat:#"http://example.com/view-videos.html?task=clip.details&id=%#",fetchid];
NSArray * activityItems = #[[NSURL URLWithString:urlString]];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
activityVC.excludedActivityTypes = #[UIActivityTypePostToFacebook,UIActivityTypePostToTwitter,UIActivityTypePostToWeibo,UIActivityTypeCopyToPasteboard,UIActivityTypeMessage];
[self presentViewController:activityVC animated:YES completion:nil];
If you want to share some video then also add that video in activityItems array object
Hope this will help you.

Why my message is shared twice in viber, I have used UIActivityViewController

I have used UIActivityViewController for sharing my message in Facebook, Twitter, Viber etc....It seems the message is send twice in Viber but for others are ok. Can u please help me?? I have used the code given below...
-(void)shareContent {
NSString * message;
NSArray * itemsArray = [NSArray new] ;
if ([shareFlag isEqualToString:#"Friend"]) {
message = #"Hi, I am using Amar Sticker, an amazing app to download & share cool Bangla Stickers. Click here and get it for FREE: http://goo.gl/qK7HRw";
NSURL *appLink = [NSURL URLWithString:#"http://goo.gl/qK7HRw"];
itemsArray = #[message, appLink];
shareFlag = #"";
}
UIActivityViewController * avc = [[UIActivityViewController alloc] initWithActivityItems:itemsArray applicationActivities:nil];
[avc setExcludedActivityTypes:#[UIActivityTypeAssignToContact, UIActivityTypeCopyToPasteboard,UIActivityTypeSaveToCameraRoll]];
[avc setCompletionHandler:^(NSString *activityType, BOOL completed) {
}];
[self presentViewController:avc animated:YES completion:nil];
}
After many searching and doing in several way I see that it only happens when I share an array, it can not handle the shared object of the array properly, maybe its a bug of viber. When I post only one string or url it can send properly. I have tested using 2,3,4 items arrry and only one single string/url etc.

Sending image to whatsapp with ActivityVC

I'm trying to share an image and text.
But when i'm trying to share using whatsapp i dont see the image and it doesnt get sent (i do see it when i'm trying to share to facebook or mail...).
Whats going on?
- (void)shareImage:(UIImage *)image
{
NSString *sharedMsg=[NSString stringWithFormat:#"Hello world"];
UIImage* sharedImg=image;
NSArray* sharedObjects=[NSArray arrayWithObjects:sharedMsg, sharedImg, nil];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc]
initWithActivityItems:sharedObjects applicationActivities:nil];
activityViewController.popoverPresentationController.sourceView = self.view;
[self presentViewController:activityViewController animated:YES completion:nil];
}
#ozd,
if image Share then
see link : Share image/text through WhatsApp in an iOS app
& if Share Text
JBWhatsAppActivity Library: https://github.com/jberlana/JBWhatsAppActivity
using Below Code You can share Text , Link..etc, may be helpful to you.
WhatsAppMessage *whatsappMsg = [[WhatsAppMessage alloc] initWithMessage:#"Hey , I would like you to experience this fabulous app which helps you to create , store and share your MOMENTS. You can add your voice message to every photo and moments too !!!\n\nDownload the app from https://play.google.com/store?hl=en" forABID:#""];
NSArray *applicationActivities = #[[[JBWhatsAppActivity alloc] init]];
NSArray *excludedActivities = #[UIActivityTypePrint, UIActivityTypePostToWeibo, UIActivityTypeMessage];
NSArray *activityItems = #[#"Hey , I would like you to experience this fabulous app which helps you to create , store and share your MOMENTS. You can add your voice message to every photo and moments too !!!\n\nDownload the app from https://play.google.com/store?hl=en", whatsappMsg];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities];
activityViewController.excludedActivityTypes = excludedActivities;
[self presentViewController:activityViewController animated:YES completion:^{}];

Add Facebook to UIActivityViewController shares

I am trying to let my iOS app to share using the UIActivityViewController, my problem is i can only share with Message and Mail . In other words the apps that are appear in the UIActivityViewController are only the Message and Mail .
How could I add the FaceBook or Twitter to them .
Here is my code
UIButton *shareButton=(UIButton*)sender;
UIActivityViewController *activityVC=[[UIActivityViewController alloc] initWithActivityItems:
#[#"Programmatically Shared post Just for testing ",
[ [videosList objectAtIndex:shareButton.tag ]videoUrl]]
applicationActivities:nil];
I am already logged in with FaceBook App and it is shown when i trying
to share using another app.
You're probably not logged in to Facebook or Twitter in the devices Settings. They won't show up here unless the user is logged in.
Looks like you are not attaching the URL perfectly :
NSString *shareText = #"Text";
NSURL *shareURL = [NSURL URLWithString:#"http://somewebsite.com"];
NSArray *items = [NSArray arrayWithObjects:
shareText,
_shareImage,
shareURL, nil];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
[activityViewController setValue:shareText forKey:#"subject"];
[self presentViewController:activityViewController animated:YES completion:nil];
NSArray* dataToShare = #[NSURL fileURLWithPath:#"file url"];
// ...or whatever pieces of data you want to share.
UIActivityViewController* activityViewController= [[UIActivityViewController alloc] initWithActivityItems:dataToShare applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:^{}];

UIActivityViewController Automatically 'Clicking' Link iOS 7

I have a basic UIActivityViewController sharing some text and a URL. The sharing options are Email, SMS, Twitter, and Facebook. Everything works fine in iOS 6 but in iOS 7 when I choose Twitter or Facebook, without touching anything my device automatically closes my app, opens Safari and goes to the URL I am trying to share. What could be causing this?
Code (CustomActivityItemProvider is a subclass to customize text based on sharer):
if ([UIActivityViewController class]) { // if class exists = ios6+
// Create array for sharing
CustomActivityItemProvider *textToShare = [[CustomActivityItemProvider alloc]
initWithStandardText:#"Text to share.\n"];
NSURL *urlToShare = iTunesShort ? iTunesShort : [NSURL URLWithString:iTunesLink];
NSArray *activityItems = #[textToShare, urlToShare];
// Show sharing view
UIActivityViewController *activityVC = [[UIActivityViewController alloc]
initWithActivityItems:activityItems applicationActivities:nil];
activityVC.excludedActivityTypes = #[UIActivityTypePrint, UIActivityTypeCopyToPasteboard,
UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll];
[self presentViewController:activityVC animated:TRUE completion:nil];
}
So I still don't know why only shortened URLs were causing this problem, but a solution that took care of it was to include the urlToShare in the textToShare.
// Create array for sharing
NSString *urlToShare = iTunesShort ? iTunesShort : iTunesLink;
NSString *textWithUrl = [NSString stringWithFormat:#"Text to share.\n%#", urlToShare];
CustomActivityItemProvider *textToShare = [[CustomActivityItemProvider alloc]
initWithStandardText:textWithUrl];
NSArray *activityItems = #[textToShare];

Resources