Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIActivityController Posting On Facebook

I have added UIActivityController in my project. Looks like there is a lot less help available on this particular topic. The problem that i am facing is that links are getting shared on the Facebook in a weird way and not the way they are shared usually on the Facebook. To make more sense, the photos along with the links are going in the iOS Photos folder without any option to change it.

Below is the example image how they are currently getting shared on Facebook:

enter image description here

How they are normally shared on Facebook and what i want:

enter image description here

Here is the code that i am using to add UIActivityController in my project:

UIActivityViewController *objVC = [[UIActivityViewController alloc]initWithActivityItems:[NSArray arrayWithObjects:titleString, [NSURL URLWithString:urlString], imageTaker, nil] applicationActivities:nil];


[self presentViewController:objVC animated:YES completion:nil];
[objVC setCompletionHandler:^(NSString *activityType, BOOL completed)
 {
     NSLog(@"Activity = %@",activityType);
     NSLog(@"Completed Status = %d",completed);

     if (completed)
     {
         UIAlertView *objalert = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"Posting was success" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
         [objalert show];
         objalert = nil;
     }else
     {
         UIAlertView *objalert = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"Posting was not successful" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
         [objalert show];
         objalert = nil;
     }
 }];

Other than that, i am also receiving some warnings in the console which are as follow:

Registering unknown app identifier com.apple.mobilemail failed
Unable to find app identifier com.apple.mobilemail
Registering unknown app identifier com.apple.MobileSMS failed
Unable to find app identifier com.apple.MobileSMS

UPDATE: I have also tried integrating REActivityController, a library to implement the same thing but with extra features, but i am facing the same issue with it.

like image 707
AJ112 Avatar asked Nov 04 '22 01:11

AJ112


1 Answers

To share a link avoid passing in the image. So use code link this:

UIActivityViewController *objVC = [[UIActivityViewController alloc]initWithActivityItems:[NSArray arrayWithObjects:[NSURL URLWithString:urlString], nil] applicationActivities:nil];

Or this:

UIActivityViewController *objVC = [[UIActivityViewController alloc]initWithActivityItems:[NSArray arrayWithObjects:titleString, [NSURL URLWithString:urlString], nil] applicationActivities:nil];

The key thing to remember is, if you specify an image then it's regarded as a photo share story and your title and url end up being similar to the photo captions. If you omit the image then it's regarded as a link share and your title becomes the message.

The eventual story renders correctly on Facebook if the link has Open Graph tags, and by rendering correctly I mean that you'll see a picture, caption, description, etc. If no Open Graph tags are embedded in the link then the link is simply displayed in the resulting story.

like image 116
C Abernathy Avatar answered Nov 11 '22 18:11

C Abernathy