iosswiftflutterdartinstagram

UIApplication.shared.canOpenURL(instagram://) returns false but app is installed


Here is the relevant part of Info.plist:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>instagram-stories</string>
    <string>snapchat</string>
    <string>facebook</string>
    <string>fb</string>
    <string>fbauth2</string>
    <string>fbshareextension</string>
    <string>fbapi</string>
    <string>facebook-reels</string>
    <string>facebook-stories</string>
    <string>fb-messenger-share-api</string>
    <string>fb-messenger</string>
    <string>instagram</string>
    <string>twitter</string>
    <string>whatsapp</string>
    <string>tg</string>
    <string>itms-apps</string>
    <string>itms-appss</string>
    <string>mailto</string>
    <string>tel</string>
</array>

I am trying on a real device. I am also using the package apinio_social_share (https://pub.dev/packages/appinio_social_share) but it also returns false. What's wrong? Or is there any other way to check if Instagram is installed on iOS?

import Flutter
import UIKit

public class InstalledAppsCheckerPlugin: NSObject, FlutterPlugin {
  public static func register(with registrar: FlutterPluginRegistrar) {
    let channel = FlutterMethodChannel(name: "app_checker", binaryMessenger: registrar.messenger())
    let instance = InstalledAppsCheckerPlugin()
    registrar.addMethodCallDelegate(instance, channel: channel)
  }

  public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
    if call.method == "isAppInstalled",
       let args = call.arguments as? [String: Any],
       let scheme = args["package"] as? String,
       let url = URL(string: "\(scheme)://") {
        let isInstalled = UIApplication.shared.canOpenURL(url)
        result(isInstalled)
    } else {
        result(FlutterMethodNotImplemented)
    }
  }
}

Solution

  • Resolved.

    Turns out, I pasted a block that included the LSApplicationQueriesSchemes key with only snap defined, and that was scheme that got recognized in place of scheme what I send.