【问题标题】:Facebook SLComposeViewController URL shows up in body if both URL and image present如果 URL 和图像都存在,Facebook SLComposeViewController URL 会显示在正文中
【发布时间】:2012-10-03 17:53:16
【问题描述】:

使用SLComposeViewController,如果图像和 URL 都存在,我在向 Facebook 发帖时会注意到奇怪的行为。具体来说,如果您同时拥有图像和 URL,则 URL 将出现在 SLComposeViewController 视图中的 Facebook 帖子正文中,紧跟在 initialText 之后,如果我执行以下操作:

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];

这显然很麻烦,因为如果 URL 很长,初始文本会被推离 SLComposeViewController 视图的可见部分,而我只能看到 URL 的后半部分:

如果我重复这个过程,这次不将图像添加到帖子中,URL 的文本根本不会方便地显示在正文中(即使它在网上正常显示)。

底线,只有当有图片 和 和 URL 时,URL 才会显示在帖子的正文中。当我使用FBNativeDialogs 时,我看到了同样的模式。

有什么方法可以通过SLComposeViewController 阻止这种行为,这样我就可以将图像和 URL 都连接到 Facebook 帖子,而不会让用户看到该网站又长又丑的 URL?显然,我可以使用任何非SLComposeViewController 解决方案(例如,设计我自己的 UI 来撰写 Facebook 帖子,使用 Facebook 已弃用的 Feed Dialog 等)。只是想知道我是否忽略了一些明显的SLComposeViewController 解决方案。

【问题讨论】:

    标签: ios facebook ios6


    【解决方案1】:

    最后,我放弃了SLComposeViewController(以及FBNativeDialogs)。它们呈现出一种很好的综合感觉,但鉴于我的帖子总是包含照片和 URL,这真的行不通。最重要的是,这些帖子没有被正确地归为来自我的应用程序。

    所以,最后,我编写了自己的用户界面并使用 Facebook SDK 3.1 FBRequestConnection,如 here 所述。我认为我们都必须制作自己的 UI 有点愚蠢,因为原生 UI 的弱点,但事实就是如此。

    【讨论】:

      【解决方案2】:
      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];
      

      【讨论】:

      • 代码格式化还是没有进展? -1 作为阅读帮助的激励:-)
      • @Tamilarasan,我看不出这段代码如何解决只有在单个 Facebook 帖子中发送 URL 和图片时才会出现的具体问题。您既没有使用 Facebook,也没有发送图片。看起来您正在尝试迭代地解决“推文长度”问题,但这不是这里的问题。不过,感谢您的宝贵时间。
      • 请格式化您的代码,并在复制和粘贴之前阅读问题。
      【解决方案3】:

      新对话框似乎是围绕您设计的,将大部分共享数据作为所提供链接指向的网站上的标签提供。像这样:

      标题:

      <title>TITLE</title>
      

      说明:

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

      图片:

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

      应用 ID:

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

      这样您只需要提供初始文本和 URL。你可以看看官方的 Youtube 应用是如何做到的,例如 Facebook 分享。

      【讨论】:

      • 这行不通,Ytbe 也一样!仔细看问题
      猜你喜欢
      • 2016-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-02
      • 1970-01-01
      • 2018-01-29
      • 1970-01-01
      相关资源
      最近更新 更多