Yozio integration in iOS (SWIFT)
Yozio is a platform to add deep and dynamic linking for the mobile developers and web developers.
I have recently tried to work around that with Yozio and found that this is very useful tool for deep linking and dynamic linking.
Let’s divide this blog in 2 main parts :
- Yozio Basic Structure and setup instructions
- Yozio integration in XCODE
- Yozio Basic Structure :
Basically yozio provides different features like deep linking, analytics, REST api etc.., I have used deep linking part of yozio and i am going to demonstrate integration of yozio in mobile app.
Step 1: Create your account in Yozio and Setup your first app like this image:

A. Add app name whatever you want
B.Add Fallback URL, it means whenever anyone click on SuperLink, user will be redirected to that URL if app is not installed
C. Add iPhone, iPad and Google play URL so when anyone click on that link user will be redirected to that link in store.
Step 2: Now create first SuperLink
SuperLink contain your metadata which you want when someone click this link and open the app. We can give a name for our purpose so we can remember if there are multiple SuperLink in one app.
Check below image to see how we can create SuperLink:

A. Add SuperLink name which is “Share Blog” in this example
B. Add metadata if you want to add like i have added its type = blog.
Step 3: Now download and integrate SDK in your code.

Now signup and setting up app is completed in Yozio and you are now in dashboard. You will see one SuperLink is created.

Step 4: Let’s setup SuperLink flow for deeplinking.
Click on Edit of SuperLink and you will see a section like “Device Flow”. Now we will define behaviour when user click on that link.
- Select iPhone in our case as we are setting up it for iOS integration. Do you want to override default settings? click on Yes. It will show flow like below image:

2. Now our iOS integration we need custom scheme which we can define in iPhone/iPod Deeplink URL : hardikshahtestingapp://
We already set iTunes URL so we does not need to add it again. If we did not added at the begin we can add it from here as well. Now that’s it just save and close it.
Everything is setup on Yozio ! Now need to setup our code in SWIFT.
2. Coding Part:
We can add Yozio in Xcode either directly add framework in xcode or using pod as well.
- To add directly, extract SDK zip and you will see “YozioIOSSDK” folder inside that. Just drag and drop that folder into xcode.
- To add using pod just add pod file and add this line,
target 'MyApp' do
pod 'YozioIOSSDK', '~> 2.1'
end
3. Now import header file in your bridging-header.h files like below,
#import “Yozio.h”
4. Add following lines in AppDelegate.Swift file and in didFinishLaunchingWithOptions method
Yozio.initializeWithAppKey(“Yozio_App_Key”, secretKey: “Yozio_Secret_Key”, newInstallMetaDataCallback: {metaData in
NSLog(“Got Meta Data from new install: %@”, metaData)
})
Also add 2 more methods to handle URL redirection in mobile app
func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool {if NSUserActivityTypeBrowsingWeb == userActivity.activityType {// track universal link that been constructed by yozio
Yozio.handleOpenURL(userActivity.webpageURL)
// This is a util function to parse meta data from query string,
// and it will filter out Yozio internal parameters which key starts with "__y".
let metaData = Yozio.getMetaDataFromDeeplink(userActivity.webpageURL)
NSLog("Got meta data from deep link: %@", metaData)// Launch main target view controller with meta data
// Utils.launchMainViewControllerWithMetaData(metaData)
}
return true
}
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {// Deliver new install meta data and track deeplinks depending on the url type.
if Yozio.handleOpenURL(url) == YOZIO_OPEN_URL_TYPE_YOZIO_NEW_INSTALL {return true
}
// This is a util function to parse meta data from query string,
// and it will filter out Yozio internal parameters which key starts with "__y".
let metaData: NSDictionary = Yozio.getMetaDataFromDeeplink(url)
NSLog("Got meta data from deep link: %@", metaData)// Add your custom code to handle meta data.
// [YourApp handleDeeplinkCallbackWithMetaData:metaData];
// Launch main target view controller with meta data
// Utils.launchMainViewControllerWithMetaData(metaData)
return true
}
5. Now add custom scheme that we added in Yozio into xcode plist file like below:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.bundleidentifier.ios</string> //App bundle identifier
<key>CFBundleURLSchemes</key>
<array>
<string>YourCustomSchemeName</string> //Which is hardikshahtestingapp in our case
</array>
</dict>
</array>
Now run and install app in device or simulator. Yozio will fetch metadata of your device and simulator and shows successful integration.
6. Now our major concern is to generate run time dymanic link. Yozio provide a RESTful API to create yozio SubLink under SuperLink so let’s create SubLink by code like below:
func createYozioLink(blogId : String, completionBlock:CompletionBlock) -> NSURLSessionDataTask!{let Yozio_App_Key = "Yozio_App_Key"
KVNProgress.showWithStatus("Creating Link...")self.completionBlock = completionBlock
let yozioLink = NSString(format: "http://api.yozio.com/v2.0/?app_key=%@&method=sub.link.create&short_url=Zh.c.c&reassign_old_alias_to_this_link=true&meta_data[blog_id]=%@",Yozio_App_Key,blogId)
let manager = AFHTTPSessionManager()
var task : NSURLSessionDataTask!
task = manager.GET(yozioLink as String, parameters: nil, success: { (task : NSURLSessionTask!, responseObject : AnyObject?) inKVNProgress.dismiss()
print(responseObject)
let dict = responseObject as! NSDictionary
let resultBody = dict.objectForKey("body") as! NSDictionarylet finalLink = "http://r.yoz.io/" + (resultBody.objectForKey("sub_link")! as! String)print(finalLink)
}, failure: { (task: NSURLSessionDataTask?, error: NSError!) inKVNProgress.dismiss()
print(error)
})
return task
}
Call this method link :
WebServiceWrapper().createYozioLink("12") { (response, error) inprint(response)
}
If you can observe WebServiceWrapper is my class where i have written createYozioLink method, I have also passed “12” as a blog id which we called metadata which we will get this back in this method
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool
when someone click on our link from anywhere and open our app. So we can use that metadata to redirect user to specific screen if we want.
In response of above createYozioLink we will get sublink parameter so you can parse and append it with main superlink URL like below
{body = {"link_alias" = "<null>";
"meta_data" = {"blog_id" = 12;
};
"sub_link" = "Zm.c.c.d";
timestamp = 1469714252553;
};
status = ok;
}
Final URL : http://r.yoz.io/ (SuperLink)+ “sub_link” = http://r.yoz.io/Zm.c.c.d
We can use it to share. To test this install app in device and open this final url in safari. It will redirect from safari to app.
That’s it ! Enjoy
Thanks