16

My iOS is 8.1.2 and I am using the UIActivityViewController for social sharing. I click on a button and allow the UIActivityViewController to present

- (IBAction)UIActivityTypeButtonClick:(id)sender {

NSString* text=@"I am sharing this text";
NSArray* sharedArray=@[text];
UIActivityViewController * activityVC=[[UIActivityViewController alloc]initWithActivityItems:sharedArray applicationActivities:nil];
activityVC.excludedActivityTypes=@[];
[self presentViewController:activityVC animated:YES completion:nil];
}

I am getting this

enter image description here

I am getting Message, Twitter, Mail, WhatsApp and a More button.
On clicking More I get this.

enter image description here Where is FACEBOOK. I have the facebook app in my iPhone and it is setup with my ID too in settings. But facebook never shows up here. Twitter does. Is this a bug or what? Please suggest

Thanks

Rajan Maheshwari
  • 14,465
  • 6
  • 64
  • 98

5 Answers5

19

I first saw this when Facebook updated their app on April 24th. Plain text sharing to Facebook isn't working as long as the Facebook app is installed. After you delete it, it's available again.

If you try to share a URL or an image together with the plain text, you will see Facebook as an option but the text field will be blank. The image or URL will attach without a problem.

I posted a sample project that reproduces this problem on github:

https://github.com/djr/UIActivityViewController-Facebook

This is not an answer, but it's pretty clear that the problem is caused by the Facebook app.

EDIT:

It's not ideal, but I created a workaround. Don't forget that you will need to attach an image or a URL for this to work.

  1. Detect if the user has the Facebook app installed. If they do, then give them some type of informational message.

    BOOL facebookIsInstalled = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fb://"]];
    BOOL isUserLoggedInWithFacebook = [SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook];
    
    if(isUserLoggedInWithFacebook && facebookIsInstalled)
    {
        // Explain that they have to copy and paste in order to share on Facebook
    }
    
  2. Create a subclass of UIActivityItemProvider and override

    - (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType
    {
        NSString *stringToShare = @"string to share";
    
        if([activityType isEqualToString:UIActivityTypePostToFacebook] ||
           [activityType isEqualToString:@"com.facebook.Facebook.ShareExtension"] ||
           [activityType.lowercaseString rangeOfString:@"facebook"].length) 
           // Because who knows when they are going to change the activityType string?
        {
            // Automatically copy the text for them
            [[UIPasteboard generalPasteboard] setString:stringToShare];
        }
    
        return stringToShare;
    }
    
  3. Tell the user that they have to paste into the Facebook text field in order to share.

  4. Blame it on Facebook.

djr
  • 264
  • 1
  • 5
  • But when we delete fb app then how can we share on fb? Little confusing? Can you please elaborate!! Thanks. – Rajan Maheshwari Apr 30 '15 at 05:49
  • I tried the sample. When deleted Fb i got the fb app in the activityviewcontroller. But what does that mean? Where it will be posted?Please help!! Thanks – Rajan Maheshwari Apr 30 '15 at 06:20
  • @Rajan You can log into Facebook in the iOS Settings app. If you are logged in there and don't have the Facebook app, the Facebook app can't stop you from attaching plain text to a post. In iOS 7 it doesn't seem to be a problem. – djr May 01 '15 at 03:03
3

I confirm what djr reported - if you have the FB app text is no longer shared. I deleted the FB app and now sharing both text and image works.

  • But when we delete fb app then how can we share on fb? Little confusing? Can you please elaborate!! Thanks. – Rajan Maheshwari Apr 30 '15 at 05:49
  • Thinking out loud: The problem could be the `activityType` Facebook sends you when you have the app is now something like `com.facebook.extensions.post`. It used to be `UIActivityTypePostToFacebook` ( and is still the case if you do not have FB installed ). Same for Gmail etc. – Webdevotion Apr 30 '15 at 17:58
3

Facebook would like you to use their SDK. They have blocked the ability to set initial text. (Not sure how.) Check out my answer in a similar post:

UIActivityViewController for Facebook not Showing Default Text

The desired solution (from Facebook) is to use their SDK.

Community
  • 1
  • 1
DeepFriedTwinkie
  • 3,865
  • 1
  • 21
  • 21
2
NSString* text=@"I am sharing this text";
NSURL *myWebsite = [NSURL URLWithString:@"http://www.website.com/"];
//  UIImage * myImage =[UIImage imageNamed:@"myImage.png"];
NSArray* sharedArray=@[text,myWebsite];
 UIActivityViewController * activityVC=[[UIActivityViewController alloc]initWithActivityItems:sharedArray applicationActivities:nil];
NSArray *excludedActivities = @[];

activityVC.excludedActivityTypes=excludedActivities;
[self presentViewController:activityVC animated:YES completion:nil];
1

To show facebook sharing button you must add a image to the array of activity items... this may be a bug on apple side but i've not seen any open radar about this issue.

Also note on iOS 8.3 text can't be added to facebook for some reason. when adding text you only be presented to a blank textfield.

UIImage *image = [UIImage imageNamed:@"__some_image__file"];

UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[image]
                                                                                     applicationActivities:nil];

[self presentViewController:activityViewController animated:YES completion:nil];
Shams Ahmed
  • 4,498
  • 4
  • 21
  • 27