srikanth kumar
srikanth kumar

Reputation: 21

How to we go inside of App from Gmail link in swift

I want to go inside of the app for particular Controller by using of Deeplinking.

I write the following code in my AppDelegate file but it don't call that method, even also but it go to every time home page only.

extension AppDelegate{
    func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {

        print("url \(url)")
        print("url host :\(url.host!)")
        print("url path :\(url.path)")


        let urlPath : String = url.path as String
        let urlHost : String = url.host as! String
        let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)

        //PickuppageControllerDeeplinking://host/inner

        if(urlHost != "mail.google.com")
        {
            print("Host is not correct")
            return false
        }

        if(urlPath == "/inner"){

            let innerPage: PickupsPageController = mainStoryboard.instantiateViewController(withIdentifier: "PickupsPageController") as! PickupsPageController
            self.window?.rootViewController = innerPage
        } else if (urlPath == "/about"){

        }
        self.window?.makeKeyAndVisible()
        return true
    }
}

Upvotes: 2

Views: 958

Answers (1)

Pavan Kotesh
Pavan Kotesh

Reputation: 144

You need to implement URL Schemes for this. Refer this link for documentation

You need to do two things

  1. Register URL Scheme in your app
  2. Handle the incoming url in App delegate Method
application(_ application: UIApplication,
                 open url: URL,
                  options: [UIApplicationOpenURLOptionsKey : Any] = [:] ) -> Bool

Upvotes: 1

Related Questions