我正在尝试在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方案答案 0 :(得分:1)
首先,您需要了解 Info.plist !您告诉编译的应用方案为instagram
:
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>instagram</string>
</array>
</dict>
这就是为什么您总是得到'true',将其删除,然后再尝试以下操作的原因:
if let instagramURL = URL(string: "instagram://app") {
if UIApplication.shared.canOpenURL(instagramURL as URL) {
print("instagram is installed")
} else {
print("instagram is not installed")
}
}else{
print("failed!")
}