【发布时间】:2019-05-14 12:03:30
【问题描述】:
我正在尝试在 Instagram 上分享图片,如果我的设备上安装了 Instagram,它可以正常工作,否则它将打开另一个与 Instagram 分享功能相同的应用程序(而不是抛出错误)。
我的 Instagram 分享代码是:
let instaFilePath = "instagram://library?AssetPath=\(url!.absoluteString)&InstagramCaption=SocialCommerce"
let instaFilePathURL = URL(string: instaFilePath)
let instagramUrl = URL(string: "instagram://app")
if UIApplication.shared.canOpenURL(instagramUrl!) {
if #available(iOS 10.0, *) {
UIApplication.shared.open(instaFilePathURL!, options: [:], completionHandler: { (completed) in
print("-----------------------(-)--------------------------\(completed)")
})
} else {
self.showMessage("This feature is not available earlier version then iOS 10.0")
}
} else {
self.showMessage("Instagram is not present in your device")
}
我在Info.plist
中使用过CFBundleURLSchemes和LSApplicationQueriesSchemes方案
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>instagram</string>
</array>
</dict>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>instagram</string>
</array>
有人对此有解决方案吗?未安装 Instagram 时,我无法将图像发布到 Instagram,我什至无法检测是否安装了 Instagram。
遵循来自 https://www.instagram.com/developer/mobile-sharing/iphone-hooks/ 的自定义 URL 方案
【问题讨论】:
-
未安装 instagram 时打开哪个应用?
-
canOpenURL:不会检查已安装的应用程序,它只会告诉您它是否可以在 Safari 中或通过应用程序打开该 URL。有效的 URL 将始终返回 true,因为系统实际上可以在某个地方打开它。 -
如果任何其他应用程序实现与 instagram 相同的自定义 url 架构,那么它是可能的
-
嗨@SPatel,我最近在三个应用程序中实现了这一点,如果没有安装 instagram 应用程序,这两个应用程序都会相互打开。
-
@ricardopereira,请查看这里instagram.com/developer/mobile-sharing/iphone-hooks
标签: ios swift instagram socialshare