Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
381 views
in Technique[技术] by (71.8m points)

ios - Facebook is not shown in UIActivityViewController but twitter does

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...