Hi friends , Good to see you after a long time.A belated Happy New Year to all of You. Today we will learn about deep linking in iOS. Using deep linking we can route to our app from safari browser.
Steps:
- Create a new Xcode Project Lets say DeepLinking.
- Now create a new class called secondViewController.swift and take a ViewController in StoryBoard and change its class to secondViewController.
- Now go to plist and define URLSchema for the app which we will use to redirect to this app.
- Now go to AppDelegate and write below method which will handle the url when triggered from safari browser.
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
let urlPath : String = url.path as String!
let urlHost : String = url.host as String!
let mainStoryboard: UIStoryboard = UIStoryboard(name: “Main”, bundle: nil)
if(urlHost != “iOStpointBlog.com”)
{
print(“Host is not correct”)
return false
}
if(urlPath == “/second”){
let secondVC: secondViewController = mainStoryboard.instantiateViewController(withIdentifier: “secondViewController”) as! secondViewController
self.window?.rootViewController = secondVC
}
self.window?.makeKeyAndVisible()
return true
}
5. Now run the app on simulator and then stop it.
6. Go to safari broswer and hit the below URL.
iOStpointBlog://iOStpointBlog.com/second
You can download the whole project from here.
Do share your reviews and comments.
Enjoy Coding 🙂
I am sure this post has touched all the internet people, its
really really pleasant paragraph on building up new web site.
LikeLike
Thanks Jimmy….
LikeLike
Happy New Year Nilesh Sir. I liked your post. It’s very interesting. Thanks for the post
LikeLike
Thanks Sir.
LikeLike