|Hybrid Integration Tutorials||Hybrid applcation bridge for iOS APIs|
Tealeaf supports both UIWebView and WKWebView classes that iOS hybrid applications use.
Note: Apple recommends using WKWebView class instead of using UIWebView (https://developer.apple.com/documentation/uikit/uiwebview). You can view our sample code here: https://github.com/ibm-watson-cxa/SampleCode_Tealeaf_iOS_WebExample.
The known supported iOS frameworks:
- Ionic 3.0 – https://ionicframework.com/docs/
You can view our sample code here: https://github.com/ibm-watson-cxa/SampleCode_Tealeaf_iOS_CXAIonic_3.
- Cordova 7.0 – https://cordova.apache.org
You can view our sample code here: https://github.com/ibm-watson-cxa/SampleCode_Tealeaf_iOS_CXACordova_7.
You are required to instrument the HTML application with Acoustic Tealeaf UI Capture library to obtain all the interactions and behaviors of the web application placed into the webview. See the Tealeaf UI Capture library for more information.
Hybrid integration tutorials
- Instrumenting the web application
- Instrumenting the native application
- If your application uses:
- Objective C, then follow the Getting started with the Acoustic Tealeaf SDK for iOS using Objective C tutorial.
- Swift, then follow the Getting started with the Acoustic Tealeaf SDK for iOS using Swift tutorial.
Note: The WebView might load at different times based on device and network, the TealeafLayoutConfig.json needs edited to capture layout when the WebView actually fires the page-loaded event. For an up-to-date example with four view controllers, see the sample code here: https://github.com/ibm-watson-cxa/SampleCode_Tealeaf_iOS_WebExample/blob/master/WebExample/WebExample/TLFResources.bundle/TealeafLayoutConfig.json. Three of the view controllers have WebViews.
The file will look like the following:
You will notice that StartViewController does not have a WebView because isWebView is set to false and numberOfWebviews is set to 0. This means that the entire view controller is captured 500 milliseconds after the view controller has loaded.
SingleWebPageViewController uses one UIWebView because isWebView is set to true, numberOfWebviews is set to 1, do is set to true, and delay is set to 500. This means that the entire view controller is captured 500 milliseconds after the WebView has loaded.
DoubleWebPageViewController uses two UIWebViews on the same view controller because isWebView is set to true, numberOfWebviews is set to 2, do is set to true, and delay is set to 500. This means the entire view controller is captured 500 milliseconds after all the WebViews have loaded.
WEWKWebViewController uses one WKWebView on the same view controller because isWebView is set to true, numberOfWebviews is set to 1, do is set to true, and delay is set to 500. This means that the entire view controller is captured 500 milliseconds after the WebView has loaded.
If you do not know the name of the view controller, you can create a session. Then review the session on the portal and look at the menu panel for the name of the view controller.
- Managing hybrid assets
You can use the Find Hybrid Package feature to manage the assets that are required to replay a hybrid mobile application.
Hybrid application bridge for iOS APIs
|Hybrid Bridge APIs|
- – (void) enableTealeafFramework;
- – (void) disableTealeafFramework;
- – (void) requestManualServerPost;
- – (BOOL) startNewTLFSession;
- – (NSString*) currentSessionId;
- – (BOOL) setConfigurableItem: (NSString*) configItem
value: (id) value;
- – (id) valueForConfiguralbeItem: (NSString*) configItem;
- – (id) defaultValueForConfigurableItem: (NSString*) value
forName: (NSString*) name;
The TLFApplicationHelper shared instance is available as the tealeafNativeApplicationHelperSharedInstance.
Example: How TLFApplicationHelper iOS API is invoked
This example shows how a native iOS API, – (void) enableTealeafFramework;, is invoked on a shared TLFApplicationHelper instance:
- – (BOOL) logEvent: (NSString*) eventName;
- – (BOOL) logEvent: (NSString*) eventName
values: (NSDictionary*) values;
- – (BOOL) logPrintScreenEvent;
The TLFCustomEvent shared instance is available as the tealeafNativeCustomEventSharedInstance.
Example: How TLFCustomEvent iOS API is invoked
This example shows how a native iOS API, – (BOOL) logEvent: (NSString*) eventName, is invoked on a shared TLFCustomEvent instance:
Two APIs that are part of the UI Capture j2 library are used in the hybrid bridge:
- TLT.logScreenCapture instructs the underlying native functionality to take a screen capture.
- TLT.registerBridgeCallbacks is used to register callback functions that are invoked by the UI Capture j2 library in specific instances. This API supports messageRedirect, screenCapture, and addRequestHeaders callbacks.
- The messageRedirect callback can be registered to redirect and intercept messages from UI Capture j2.
Example: Function call for all of the iOS native APIs
This function in this example, function runiOS7BridgeNativeTealeafAPIs (), shows how to call all of the iOS native APIs: