Reputation: 2669
I am trying to share Images on Instagram, it's working fine if Instagram is installed on my device, otherwise it will open another app which has the same functionality as Instagram sharing (instead of error throwing).
My Instagram sharing Code is:
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")
}
I have used CFBundleURLSchemes
and LSApplicationQueriesSchemes
scheme in Info.plist
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>instagram</string>
</array>
</dict>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>instagram</string>
</array>
Does anyone have a solution for this? I can't post images to Instagram when Instagram is not installed, I can't even detect if Instagram is installed or not.
Following custom URL Scheme from: https://www.instagram.com/developer/mobile-sharing/iphone-hooks/
Upvotes: 3
Views: 643
Reputation: 7367
First of all, you need to understand Info.plist! You are telling to the compiled your app scheme is instagram
:
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>instagram</string>
</array>
</dict>
This is why you always get 'true', remove it, then try again with this:
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!")
}
Upvotes: 1