是否存在URL方案,通过该URL方案,可以使用预先选择的给定媒体和预选消息来打开Twitter应用程序?
我知道以下内容存在:
twitter://post?message=hello%20world
您还可以指定一个帐户:
twitter://post?message=hello%20world&account=helloworld
我希望能够使用用户相机胶卷中的预选图像或视频以及一条消息来打开Twitter。
复制我这个问题的答案
这种事情过去是使用Twitter Kit完成的,但是 Twitter放弃了对 TwitterKit 的支持。
2018 年 10 月 31 日,我们将不再积极为 GitHub 上的开源 SDK(iOS、Android、Unity)做出贡献,也不再接受问题和拉取请求。在此日期之后,我们还将停止通过 Cocoapods、Carthage 和 Bintray JCenter 发布 SDK。GitHub 上所有三个 SDK 的文档和源代码仍以存档状态可供使用。
此外,使用 Twitter 工具包需要您拥有 Twitter 应用程序,并且用户授予您的 Twitter 应用程序访问其帐户信息的权限。
我能够使用Branch.io深层链接解决这个问题。
总长DR
info.plist LSApplicationQueriesSchemestwitter://post?message=\(myBranchUrl)您可以在此处找到有关将 Branch 集成到 iOS 项目的更多信息
您还可以查看下面的一些示例代码:
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
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1099 次 |
| 最近记录: |