iOS

Install SDK in Morpheus Environment

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

After applying the IMQA agent code with reference to the IMQA MPM Installation Guide, please follow further the instructions of this document.

1. Add Podfile

Write the following in your project Podfile.

pod 'IMQACrashAgent', '~> 3.24.1' 
pod 'IMQAMPMAgent', '~> 3.24.1'

2. Modify PPHybridViewController

Modify the viewWillAppear code and userContentController.

viewWillAppear
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    NSLog(@"PPHybridViewController viewWillAppear");
    [_poperaWebview.configuration.userContentController addScriptMessageHandler:self name:@"ImqaBridge"];
}
userContentController
- (void)userContentController:(nonnull WKUserContentController *)userContentController didReceiveScriptMessage:(nonnull WKScriptMessage *)message {
    if([message body]) {
        if([message.name isEqual: @"ImqaBridge"]) {
           [[IMQAMpm sharedInstance] saveWebviewPostMessage:self :message.body];
         }
        NSLog(@"[message body] = %@", [message body]);
        NSDictionary *dictJson;
        if([[message body] isKindOfClass:[NSDictionary class]]) {
            dictJson = [message body];
            
        } else {
            NSData *jsonData = [[message body] dataUsingEncoding:NSUTF8StringEncoding];
            //colors is a NSArray property used as dataSource of TableView
            dictJson = [NSJSONSerialization JSONObjectWithData:jsonData
                                                       options:NSJSONReadingMutableContainers
                                                       error:nil];
        }
    }
    else{
        NSLog(@"Invalid JavaScript request.");
    }
}

Register WebView Agent

Morpheus drops static files inside the mobile instead of fetching mobile pages from the server. Place the WebView agent for Morpheus we provide at the top of the head on all pages. Due to the structure of Morpheus, we recommend not using cdn but injecting the resources by yourself.

Last updated