iOS Twitter URL Scheme将在推文中预先填充媒体

问题描述 投票:5回答:1

是否有一个URL方案,通过该方案,人们可​​以使用预先选择的特定媒体片段打开推特应用程序以及预先选择的消息?

我知道存在以下情况:

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

你也可以指定一个帐户:

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

我希望能够在用户相机胶卷中打开带有预先选择的图像或视频的推特以及消息。

ios twitter
1个回答
0
投票

this question复制我的答案

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

在2018年10月31日,我们将不再对GitHub上的开源SDK(iOS,Android,Unity)做出积极贡献或接受问题并提出请求。在此日期之后,我们还将停止通过Cocoapods,Carthage和Bintray JCenter发布SDK。 GitHub上所有三个SDK的文档和源代码仍可在存档状态下使用。

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

我能够使用Branch.io深度链接解决这个问题。

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应用程序,看起来像这样:enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.