TLMetaResolver 0.1.4

TLMetaResolver 0.1.4

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Feb 2016
SPMSupports SPM

Maintained by Bruno Berisso.



  • By
  • BrunoBerisso

TLMetaResolver

TLMetaResolver is an extension to UIWebView writen in Swift that adds the ability to parse the meta tags in the loaded web page and extract information about a native app that can be deep linked from that page. This method is used for Twitter and Facebook to deep link to a native app from a posted web page. The meta tags definitions handled for TLMetaResolver are:

How it works

TLMetaResolver adds a funtion to UIWebView that evaluate a JavaScript script in the context of the loaded web page. This script returns an app id and url. The app id is the id of the native app on iTunes, the url is a special url used to fire the native app.

With the app id the extension perform a search on iTunes calling the iTunes Search API to get the app name and icon url. Then the icon image is downloaded and a TLNativeAppInfo object is created and returned in a callback. This object can be used to create a TLNativeAppActivity to be presented in a UIActivityViewController. When the activity is performed a call to UIApplication.sharedApplication().openURL() is made with the url pointing to the native app.

Usage

You need to call one of the resolveMetaTags() functions once your page is loaded and provide a closure conforming the TLMetaResolverComplete type. Check the example project for a possible implementation, you can pod try TLMetaResolver.

One key point to remember is that webViewDidFinishLoad function of UIWebViewDelegate can be called many times so you should handle that case to avoid unnecesary calls to resolveMetaTags(). TLMetaResolver don’t perform any special consideration at that level.

There are two version of resolveMetaTags() that have slightly different parameters:

func resolveMetaTags (onComplete: TLMetaResolverComplete)

Both versions has a parameter of type TLMetaResolvercomplete that is a callback that is fired when the process finish.

func resolveMetaTags (fetchUrl: TLMetaResolverFetchURL?, _ fetchImage: TLMetaResolverFetchURL?, _ onComplete: TLMetaResolverComplete)

The long version has two extra parameters that are closures used to issue the requests to iTunes Search API (fetchUrl) and the app icon download (fetchImage). You can provide the implementation for one of this, both or none (that is the case of the short version of resolverMetaTags()). For the closures you don’t provide a default implementation is provided using NSURLSession.sharedSession().

Installation

You can also do a quick check with:

pod try TLMetaResolver

Or opt to clone the repo and integrate the code and assets under the Pod/ directory to your project as you like.

Requirements

iOS >= 8.0

Author

BrunoBerisso, [email protected]

License

TLMetaResolver is available under the MIT license. See the LICENSE file for more info.