iOS

This document provides instructions on how to apply IMQA SDK in the Cordova environment.

1. Installing SDK

1. Open the <PROJECT-NAME>.xcworkspace file.

2. Create a folder called frameworks under the ios folder.

3. Install the desired version of the framework from the link below and move the framework files to the frameworks folder in Xcode, checking Copy Items If Needed.

4. In the project settings, set all frameworks to Embed & Sign in Frameworks, Libraries, and Embedded Content.

2. Setting SDK

1. Import two below from the AppDelegate.h file.

AppDelegate.m
#import <IMQAMPMAgent/IMQAMPMAgent.h>
#import <IMQACrashAgent/IMQACrash.h>

2. In the AppDelegate.m file, add the code below to the top of - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions.

AppDelegate.m
NSString* PROJECT_KEY = @"<PROJECT_KEY>";

IMQACrashConfiguration* crashConfig = [[IMQACrashConfiguration alloc] initWithApiKey:PROJECT_KEY];
[IMQACrash startWithConfiguration:crashConfig];

IMQAConfig* mpmConfig = [[IMQAConfig alloc] init:PROJECT_KEY];
[[IMQAMpm sharedInstance] runWithConfig:mpmConfig];

3. If you see the log like below when running it after buildup, the installation is completed successfully.

AppDelegate.m
[IMQACrash] [INFO] Sent session AC868F82-97E7-4DAA-A75B-E6E5CEB64F46

[IMQA] (1/4) Start tracking viewcontroller
[IMQA] (2/4) Start tracking network
[IMQA] (3/4) Start tracking resource
[IMQA] (4/4) Start tracking backtrace
[IMQA] (4/4) Complete setting IMQA MPM
[IMQA] IMQA MPM Version : <VERSION>

3. Cordova Setup

1. Install WebView Agent at the top of your HTML. (Requires a build after installation)

index.html
<!-- IMQA Webview Agent(ver. 1.1.3 earlier) -->
<script type="text/javascript" src="https://imqawebviewagent.blob.core.windows.net/agent/webview-agent-1.1.2.js"
crossorigin></script>

// If you want to apply it as a min file:
<script type="text/javascript" src="https://imqawebviewagent.blob.core.windows.net/agent/webview-agent-1.1.2.min.js"
crossorigin></script>
index.html
<!-- IMQA Webview Agent (ver. 1.1.3 later) -->
<script type="text/javascript" src="https://cdn.imqa.io/agent/webview-agent-1.1.3.js"
crossorigin></script>

<script>
    ((w, c, _wv, _w, _wk, _mh, _b) => {        
       w[_wv](w); // Webview Agent Execution Function
    })(window, 'imqaClientConfig', 'IMQAWebviewMain', 'IMQAWebMain', 'webkit', 'messageHandlers', 'ImqaBridge')
</script>

2. In Xcode, locate the CordovaLib/Private/Plugins/CDVWebViewEngine/CDVWebViewEngine.m file.

3. Import MPM SDK at the top in CDVWebViewEngine.m.

CDVWebViewEngine.m
#import <IMQAMPMAgent/IMQAMPMAgent.h>

4. In - (void)pluginInitialize, find a part that modifies WKUserContentController and modify it.

CDVWebViewEngine.m
// existing code
WKUserContentController* userContentController = [[WKUserContentController alloc] init];
[userContentController addScriptMessageHandler:weakScriptMessageHandler name:CDV_BRIDGE_NAME];
// additional code
[userContentController addScriptMessageHandler:self name:@"ImqaBridge"];

5. Find and modify - (void)userContentController:(WKUserContentController*)userContentController didReceiveScriptMessage:(WKScriptMessage*)message.

***Must be added to the very top of that function.***

CDVWebViewEngine.m
if([message.name isEqual: @"ImqaBridge"]) {
 [[IMQAMpm sharedInstance] saveWebviewPostMessage:(CDVViewController*)self.viewController :message.body];
}

Last updated