# iOS

{% hint style="warning" %}
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.
{% endhint %}

## 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.

{% code title="viewWillAppear" %}

```objectivec
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    NSLog(@"PPHybridViewController viewWillAppear");
    [_poperaWebview.configuration.userContentController addScriptMessageHandler:self name:@"ImqaBridge"];
}
```

{% endcode %}

{% code title="userContentController" %}

```objectivec
- (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.");
    }
}
```

{% endcode %}

## 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.imqa.io/imqa-guide/eng/installation-guide/morpheus/ios.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
