The following steps should be performed in order to configure Swap Links.
On all storyboards, a segue should connect from the Searched User Profile View Controller to the Container View Controller (The Profile View Controller). The segue identifier should be named something like fromSearchUsersToProfile.
Next thing is to configure the Branch SDK to respond to a universal swap link. Replace the branch?.initSession completion block that's already in app delegate with this:
branch?.initSession(launchOptions: launchOptions, andRegisterDeepLinkHandler: { (param, error) in
if error == nil{
// opened by swap link
if let swapLink = param?["+non_branch_link"] as? String{
if isSignedIn(){
if swapLink.contains("/VP"){ // VP verification links should be in the form http://swapapp.co/VP/###### where ###### is the VP code
let code = getUsernameFromSwapLink(swapLink: swapLink)
SwapUser().getInformation(completion: { (error, user) in
DispatchQueue.main.async {
if user != nil {
// Valid Swap Link or VP Code
if let VPcode = user?._VPCode{
if VPcode == code{
// Verify account
SwapUser().set(isVerified: true)
}
}
}
}
})
}
else {
let username = getUsernameFromSwapLink(swapLink: swapLink)
searchedUser = username // Pass the username to the searched user view controller
let TabBarVC = storyboard.instantiateViewController(withIdentifier: "SearchUsersTabBarController")
var SearchedProfileVC = storyboard.instantiateViewController(withIdentifier: "SearchedUserProfileViewController")
TabBarVC.present(SearchedProfileVC, animated: false)
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window!.rootViewController = TabBarVC
self.window!.backgroundColor = UIColor.white
self.window!.makeKeyAndVisible()
}
}
}
}
})
Next, we have to go to the Searched User Profile View Controller because the 'X' button will not work because if we open it from a universal link, it does not have a presented VC so we must use the segue to go back to the Profile View Controller if it is opened from a universal link.
@IBAction func didTapBack(_ sender: Any) {
if self.presentingViewController == nil{
self.performSegue(withIdentifier: "fromSearchUsersToProfile", sender: nil)
} else{
dismiss(animated: true, completion: nil)
}
} // If it does not have a presenting view controller, it will segue rather than dismiss.
We also have to handle the case that a user opens an invalid swap link for a user that does not exist. Therefore, in the SwapUser().getInformation block, add this code.
The following steps should be performed in order to configure Swap Links.
On all storyboards, a segue should connect from the Searched User Profile View Controller to the Container View Controller (The Profile View Controller). The segue identifier should be named something like fromSearchUsersToProfile.
Next thing is to configure the Branch SDK to respond to a universal swap link. Replace the branch?.initSession completion block that's already in app delegate with this:
Next, we have to go to the Searched User Profile View Controller because the 'X' button will not work because if we open it from a universal link, it does not have a presented VC so we must use the segue to go back to the Profile View Controller if it is opened from a universal link.
We also have to handle the case that a user opens an invalid swap link for a user that does not exist. Therefore, in the SwapUser().getInformation block, add this code.