【问题标题】:iOS Twitter URL Scheme which will pre-populate media in a tweetiOS Twitter URL Scheme,它将在推文中预先填充媒体
【发布时间】:2015-07-26 19:20:13
【问题描述】:

是否有一个 URL 方案,人们可​​以通过它打开 twitter 应用程序,其中预先选择了给定的媒体片段以与预先选择的消息一起发布?

我知道存在以下内容:

twitter://post?message=hello%20world

您还可以指定一个帐户:

twitter://post?message=hello%20world&account=helloworld

我希望能够打开 twitter,其中包含用户相机胶卷中预先选择的图像或视频以及一条消息。

【问题讨论】:

  • SLComposeViewController 会接近你想要做的事情吗?
  • @LouisTur 特别希望促进将视频本地发布到 Twitter。 SLComposeViewController 是在 iOS 6 左右创建的,我相信……在 Twitter 允许视频之前。
  • @PiotrTomasik 你找到解决方案了吗?
  • 我相信这可以通过instagram应用发布视频/图像来完成,所以在技术上是可行的,但我不知道twitter是否实现。我怀疑唯一的方法是通过他们的标准休息 API。我什至找不到他们的 twitter:// url 方案的文档。

标签: ios twitter


【解决方案1】:

this question复制我的答案

这种事情曾经使用Twitter Kit 来完成,但是,Twitterdropped support 用于 TwitterKit。

从 2018 年 10 月 31 日起,我们将不再积极参与 GitHub 上的开源 SDK(iOS、Android、Unity),或接受问题和拉取请求。在此日期之后,我们还将停止通过 Cocoapods、Carthage 和 Bintray JCenter 发布 SDK。 GitHub 上所有三个 SDK 的文档和源代码将在存档状态下继续使用。

此外,使用 Twitter 工具包需要您拥有 Twitter 应用程序并且用户授予您的 Twitter 应用程序访问其帐户信息的权限。

我能够使用Branch.io deep-links 解决这个问题。

TLDR

  1. 将分支 SDK 添加到您的项目中。
  2. 使用要共享的图像的 url 和任何其他附加信息创建一个分支 url。
  3. 将“twitter”添加到您的应用程序info.plist LSApplicationQueriesSchemes
  4. 使用引用 in this answer 的默认深层链接将该链接分享到 Twitter。示例:twitter://post?message=\(myBranchUrl)

您可以找到更多关于将 Branch 集成到您的 iOS 项目中的信息here

您还可以查看下面的一些示例代码:

let buo = BranchUniversalObject.init(canonicalIdentifier: "content/12345")
buo.title = "My Content Title"
buo.contentDescription = "My Content Description"
buo.imageUrl = "https://lorempixel.com/400/400"
buo.publiclyIndex = true
buo.locallyIndex = true
buo.contentMetadata.customMetadata["key1"] = "value1"

let lp: BranchLinkProperties = BranchLinkProperties()
lp.channel = "facebook"
lp.feature = "sharing"
lp.campaign = "content 123 launch"
lp.stage = "new user"
lp.tags = ["one", "two", "three"]

lp.addControlParam("$desktop_url", withValue: "http://example.com/desktop")
lp.addControlParam("$ios_url", withValue: "http://example.com/ios")
lp.addControlParam("$ipad_url", withValue: "http://example.com/ios")
lp.addControlParam("$android_url", withValue: "http://example.com/android")
lp.addControlParam("$match_duration", withValue: "2000")

lp.addControlParam("custom_data", withValue: "yes")
lp.addControlParam("look_at", withValue: "this")
lp.addControlParam("nav_to", withValue: "over here")
lp.addControlParam("random", withValue: UUID.init().uuidString)

buo.getShortUrl(with: lp) { [weak self] (url, error) in
    if let err = error {
        // Handle Error
    }

    if let branchUrl = url, let urlScheme = URL(string: "twitter://post?message=\(branchUrl)") {
        if UIApplication.shared.canOpenURL(urlScheme) {
            UIApplication.shared.open(urlScheme, options: [:], completionHandler: nil)
        } else {
            // Twitter not installed
        }
    } else {
        // Url Error
    }
}

这会打开 Twitter 应用程序,如下所示:

【讨论】:

    猜你喜欢
    • 2015-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-28
    • 1970-01-01
    • 2022-06-21
    相关资源
    最近更新 更多