点按共享图像打开 URL
Posted
技术标签:
【中文标题】点按共享图像打开 URL【英文标题】:Shared image open URL on tap 【发布时间】:2019-03-05 14:57:08 【问题描述】:我正在使用 - FBSDKShareKit (4.40.0): 我想在 Facebook 上分享图片。它应该是可点击的,并且应该像 Endomondo 应用程序一样打开网站。
我试过这段代码,但 url 覆盖了照片,它们没有显示:
let sharePhoto = FBSDKSharePhoto()
sharePhoto.image = someImage
let content = FBSDKSharePhotoContent()
content.photos = [sharePhoto];
content.contentURL = URL(string: "https://facebook.com")!
FBSDKShareDialog.show(from: self, with: content, delegate: nil)
他们是怎么做到的?
【问题讨论】:
您正在查看的内容似乎不是一个照片共享开始 - 它可能只是一个共享 链接,它具有通过 OG 元指定的标题、描述和缩略图标签。 【参考方案1】:用它在 Facebook 上分享
导入社交
func shareToFb(_ yourImage:UIImage!)
let facebookURL = URL(string: "fb://")
if (UIApplication.shared.canOpenURL(facebookURL!))
let vc = SLComposeViewController(forServiceType:SLServiceTypeFacebook)
vc?.add(yourImage)
vc?.setInitialText("Initial text here.")
self.present(vc!, animated: true, completion: nil)
else
let urlStr = "https://itunes.apple.com/us/app/workplace-by-facebook/id944921229?mt=8"
if #available(ios 10.0, *)
UIApplication.shared.open(URL(string: urlStr)!, options: [:], completionHandler: nil)
else
UIApplication.shared.openURL(URL(string: urlStr)!)
【讨论】:
【参考方案2】:看来@04FS 是对的。它只是一个 og:image。他们将图片发送到服务器,然后生成一个带有 html 元标记的页面。 (之间有一个重定向,所以对我来说并不明显)
<meta property="fb:app_id" content="202423869273" />
<meta property="al:ios:url" content="endoapp://workouts" />
<meta property="al:ios:app_store_id" content="333210180" />
<meta property="al:ios:app_name" content="Endomondo Sports Tracker" />
<meta property="al:android:class" content="com.endomondo.android.EndoSplash" />
<meta property="al:android:package" content="com.endomondo.android" />
<meta property="al:android:app_name" content="Endomondo Sports Tracker" />
<meta property="og:type" content="endoapp:workout" />
<meta property="og:url" content="https://www.endomondo.com/users/11394222/workouts/1278713145?country=pl&lang=en&measure=metric" />
<meta property="og:title" content="0.02 km run" />
<meta property="og:description" content="(brak nazwy) ran 0.02 km using Endomondo." />
<meta property="og:locale" content="en_US" />
<meta property="og:site_name" content="Endomondo" />
<meta property="og:determiner" content="auto" />
<meta property="og:image" content="https://www.endomondo.com/resources/gfx/image/69040478/06074879f4cd011f6b7b8cfa028e146b/big.jpg" />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
<meta property="endoapp:duration" content="38" />
<meta property="endoapp:distance" content="0.02" />
<meta property="endoapp:sport" content="https://www.endomondo.com/facebook/sport/0?country=pl&lang=en&measure=metric" />
<meta property="endoapp:unit" content="km" />
<meta property="endoapp:maxspeed" content="6.4" />
<meta property="endoapp:avgspeed" content="1.5" />
<meta property="endoapp:avg_speed" content="39:16" />
<meta property="endoapp:avg_speed_unit" content="min/km" />
<meta property="endoapp:calories" content="2" />
<meta property="endoapp:route:latitude" content="54.19036" />
<meta property="endoapp:route:longitude" content="16.17868" />
<meta property="endoapp:route:altitude" content="0.01" />
<meta property="endoapp:route:latitude" content="54.19023" />
<meta property="endoapp:route:longitude" content="16.17856" />
<meta property="endoapp:route:altitude" content="0.01" />
【讨论】:
以上是关于点按共享图像打开 URL的主要内容,如果未能解决你的问题,请参考以下文章
Google Plus Open Graph 错误:当 UTM 或其他查询字符串附加到 URL 时,G+ 无法识别打开的图形图像