2

示例项目:http ://cl.ly/261z1P100T25

在 iOS 7 下,当我尝试将 URL 添加到推文时,如果没有足够的空间来添加它,该方法应该返回 NO(“如果 url 不适合当前可用的字符空间,此方法返回 NO”)但是这个方法在 iOS 7 中总是返回 YES。例如,在以下示例中,“无法添加”。永远不会打印,并且推文显示剩余 -32 个字符。

SLComposeViewController *twitterViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
NSString *titleToShare = @"i am a string a super string the most super string that ever existed in the world of the super string universe which as it happens is very super as well";

if (titleToShare.length > 140) {
    titleToShare = [titleToShare substringToIndex:140];
}

[twitterViewController setInitialText:titleToShare];

if (![twitterViewController addURL:[NSURL URLWithString:@"http://google.com"]]) {
    NSLog(@"Couldn't add.");
}

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

它坏了吗?我必须围绕这个编码吗?

4

1 回答 1

0

它没有损坏,只是没有很好地公开记录。我在 setInitialText: 方法的注释后面的代码中发现:

// Sets the initial text to be posted. Returns NO if the sheet has already been
// presented to the user. On iOS 6.x, this returns NO if the specified text
// will not fit within the character space currently available; on iOS 7.0 and
// later, you may supply text with a length greater than the service supports,
// and the sheet will allow the user to edit it accordingly.

因此,它们允许您设置大于 140 个字符的文本,只是您不能发布此文本,因为发布按钮被禁用。

于 2013-11-11T01:23:24.093 回答