Facebook SLComposeViewController URL shows up in b

2019-02-12 14:32发布

Using SLComposeViewController, I notice curious behavior when posting to Facebook if both the image and the URL are present. Specifically, if you have both image and URL, the URL appears in the body of the Facebook post in the view of the SLComposeViewController, immediately after the initialText if I do the following:

SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

NSString *text = @"This is a test Facebook post with SLComposeViewController.";
NSURL *url = [NSURL URLWithString:@"http://http://stackoverflow.com/questions/12503287/tutorial-for-slcomposeviewcontroller-sharing"];
UIImage *image = ...;

[controller setInitialText:text];
[controller addURL:url];
[controller addImage:image];

[self presentViewController:controller animated:YES completion:nil];

That's obviously a hassle because the if the URL is long, the initial text is pushed off of the visible portion of the view of SLComposeViewController and I only see the latter portion of the URL:

enter image description here

If I repeat this process, this time not adding the image to the post, the text of the URL conveniently does not show up in the body at all (even though it shows up properly online).

enter image description here

Bottom line, only if there is an image and and URL does the URL show up in the body of the post. And I see this same pattern when I use FBNativeDialogs.

Is there any way to stop that behavior with SLComposeViewController, so that I can have both image and URL connected to the Facebook post without exposing the user to the web site's long, ugly URL? Clearly I can use any of the non-SLComposeViewController solutions (e.g. design my own UI for composing the Facebook post, using Facebook's deprecated Feed Dialog, etc.). Just wondering if I'm overlooking some obvious SLComposeViewController solution.

3条回答
祖国的老花朵
2楼-- · 2019-02-12 14:49

The new dialog seems to be designed around you providing most of the share data as tags on the website the provided link points to. Like this:

Title:

<title>TITLE</title>

Description:

<meta name="description" content="DESCRIPTION">

Image:

<meta property="og:image" content="IMAGE_URL">

App ID:

<meta property="fb:app_id" content="APP_ID">

This way you only need to provide the initial text and an URL. You can look how the official Youtube app does it's Facebook sharing for an example.

查看更多
乱世女痞
3楼-- · 2019-02-12 15:14

In the end, I've given up on the SLComposeViewController (as well as the FBNativeDialogs). They present a nice, integrated feel, but given that my posts invariably include both photo and URL, this really doesn't work. On top of that, the posts were not correctly attributed as being from my app.

So, in the end, I've written my own user interface and use the the Facebook SDK 3.1 FBRequestConnection as outlined here. I think it's a little silly that we all have to make our own UI because the weaknesses in the native UI, but it is what it is.

查看更多
再贱就再见
4楼-- · 2019-02-12 15:14
TWTweetComposeViewController *twitter = [[TWTweetComposeViewController alloc] init];
NSString *format = @"“%@” %@ /via @DesignSceneApp";
NSString *message = [NSString stringWithFormat:format, title, url]
NSUInteger idx = title.length;
while (![twitter setInitialText:message]) {
    idx -= 5;
    if (idx > 5) {
        message = [NSString stringWithFormat:format,
            [NSString stringWithFormat:@"%@…", [title substringToIndex:idx]],
            url
        ];
    } else {
        // Give up on the title.
        message = [NSString stringWithFormat:@"%@ /via @DesignSceneApp", url];
        [twitter setInitialText:message];
        break;
    }
}

[self presentViewController:twitter animated:YES completion:nil];
查看更多
登录 后发表回答