iOS SLComposeViewController - Twitter发布时URL未显示

8

我正在使用SLComposeViewController来发布Twitter和Facebook的帖子。我在Twitter和Facebook上都使用了相同的代码,但是URL在Twitter的帖子中没有显示出来。我该如何解决这个问题?

enter image description here

Twitter代码 -

socialController = [SLComposeViewController
    composeViewControllerForServiceType:SLServiceTypeTwitter];
[socialController setInitialText:@"Testing: This is the app link!"];
[socialController addImage:[UIImage imageNamed:@"image.jpg"]];
[socialController addURL:[NSURL URLWithString:@"http://www.google.com"]];
[self presentViewController:socialController animated:YES completion:nil];

Facebook代码-

socialController = [SLComposeViewController
    composeViewControllerForServiceType:SLServiceTypeFacebook];
[socialController setInitialText:@"Testing: This is the app link!"];
[socialController addImage:[UIImage imageNamed:@"image.jpg"]];
[socialController addURL:[NSURL URLWithString:@"http://www.google.com"]];
[self presentViewController:socialController animated:YES completion:nil];

1
很确定那就是它的工作方式。你在推文对话框中看到的小纸夹表示有一个链接附加在其中。Facebook没有API让你同时上传图片和分享链接,所以链接必须放在消息正文中。 - Ming Li
我还没有使用addURL,但是这个方法可能对你有帮助:如果你想在推文中看到链接,请尝试将链接添加到initialText中:[socialController setInitialText:[NSString stringWithFormat: @"测试:这是应用程序链接!%@", tweetURL]]; - Sawsan
5个回答

15

SLComposeViewController会在推文编辑视图上以附件的形式显示URL。当发送推文时,URL将附加在帖子的末尾。您甚至可以添加多个URL,它们仍然会显示为附件。因此,这就是应该的方式,没有任何需要修复的问题。


1
  • 我建议您实际发送推文,并检查您的Twitter帐户是否真的缺少URL(它可能正常工作)

  • 显然这不是导致您麻烦的原因,但要注意消息长度:我发现当文本消息太长时,Twitter API会悄悄跳过应该包含缩短的图像和URL的步骤。根据this answer,如果您两次使用addURL,则您的文本不应超过113个字符。


1
我建议您参考this链接。调试您的代码,有一个方法- (BOOL)addURL:(NSURL *)url,它返回一个布尔值,表示是否成功添加了URL。

0

SLComposeViewController的-addURL:方法返回一个BOOL值,以指示您尝试附加的URL是否适合剩余的字符空间。修改您的代码以检查它是否实际上返回了NO

BOOL urlOK = [socialController addURL:[NSURL URLWithString:@"http://www.google.com"]];
if(!urlOK) {
 //Notify the user, truncate the message, or something else depending on your use case
}

0

如果你包含一个链接,Twitter现在将限制推文长度为117个字符


这应该是一个注释。 - ρяσѕρєя K

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接