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:
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.
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
TLMetaResolver is available through CocoaPods. To install it, simply add the following line to your Podfile:
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.
iOS >= 8.0
TLMetaResolver is available under the MIT license. See the LICENSE file for more info.