linkedin / linkedin.github.com

Listing of all our public GitHub projects.
59 stars 52 forks source link

[iOS] While passing the LinkedIn profile url to open the LinkedIn profile in LinkedIn app, it's opening in web #27

Open swarna456 opened 8 months ago

swarna456 commented 8 months ago

I want to open the profile of LinkedIn in LinkedIn app if app is installed otherwise in web. So, I added the code like this:

if let linkedIn = "https://www.linkedin.com/in/prakashiyerleadershipcoach" {
                            guard let linkedInAppURL =  URL(string: "linkedin:\(linkedIn)")
                            else { fatalError(Localize.validUrlExpectedMsg) }
 UIApplication.shared.open(linkedInURL, options: [:], completionHandler: nil)
                        }

Always it's redirecting to web only even if the app is installed.

I tried to resolve this issue using deep linking

let linkedIn = "https://www.linkedin.com/in/prakashiyerleadershipcoach"
            guard let linkedInAppURL =  URL(string: "linkedin://profile/prakashiyerleadershipcoach")
            else { fatalError("Invalid linkedInAppURL") }
            guard let linkedInWebURL = URL(string: (linkedIn.removingPercentEncoding)!)
            else { fatalError("Invalid linkedInWebURL") }
            if UIApplication.shared.canOpenURL(linkedInAppURL) {
                UIApplication.shared.open(linkedInAppURL)
                print("linkedinnnnn == \(linkedInAppURL)")
            } else {
                UIApplication.shared.open(linkedInWebURL, options: [:], completionHandler: nil)
                print("linkedinnnnn == \(linkedInWebURL)")
            }
}

Added LSApplicationQueriesSchemes in info.plist file

    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>linkedin</string>
    </array>

Now while clicking on link profile page is opening in app if app is installed otherwise opening in web. But this is not the official URL schemes provided by linkedIn. I need the permanent solution for that. Can anyone help me in that. Thanks in advance!