ios - 使用 SLServiceTypeTwitter 时,链接的最长长度是多少?如何设置推文的格式以确保它不会更长?

标签 ios objective-c twitter ios6 ios7

现在,当用户选择一篇文章通过 Twitter 分享时,我想提供链接和 URL 的标题,但我很难确定链接在 Twitter 中的长度。

通过 iOS API 与 Twitter 共享的链接是否计为 URL 的完整长度,或者它是 URL 的地方,给定特殊规则/长度?如果是这样,我如何计算长度。我读过一些文章说链接被认为是 22 个字符长,但最近从 20 个字符更改为 20 个字符。如果它再次更改怎么办?

那么一个链接有多长呢?一旦我弄清楚了,我是否应该只使用 140 - link length 来计算标题要使用多少个字符?

最佳答案

根据 twitter docs ,所有 URL 都使用他们的 t.co 服务缩短 - 包括那些通过 SLComposeViewController 提交的。文档说,如果您尝试将长 URL 添加到 SLComposeViewController,它将根据可用空间成功或失败,并且在做出此决定时使用的是缩短的 URL。

他们不会给您一个字符数,但会告诉您您要添加的内容是否适合。

摘自链接的 Twitter 文档,强调我的:

Below is an example of the above steps. Note that the methods for setting initial content respond with Boolean values; this allows you, the developer, to not have to worry about the current count of characters in the body of the Tweet that you are initializing. If the method returns YES, there was enough room to add the content. If the method returns NO, the content you attempted to add would result in a Tweet longer than 140 characters. The logic for character counting also takes into effect the current number of characters required for t.co URL wrapping.

我没有尝试过,但您可以通过迭代调用 setInitialText 来确定首次添加 URL 后可用的字符数:使用字符数递减的字符串,从 140 个字符开始。

关于ios - 使用 SLServiceTypeTwitter 时,链接的最长长度是多少?如何设置推文的格式以确保它不会更长?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19625055/

相关文章:

iphone - iOS 7 UItableview 单元格背景 View

iOS 在另一个应用程序中打开 PDF 文件

iphone - 无法同时满足约束

ios - 带有圆角的 UIButton 允许在角落进行交互

javascript - 有没有什么方法可以不使用 tweetbox 直接点击一个按钮来发推文?

ios - 如何在 swift 字符串变量中使用不可打印的字符?

ios - 应用版本重复

objective-c - Objective C - 子类化 NSArray

ruby - 在命令行中使用 t 回复推文

iphone - Twitter 引擎 SA_OAuthTwitterEngine 集成?