# iOS

{% hint style="warning" %}
Morpheus環境におけるIMQA SDKを適用する方法を提供します。

[IMQA MPMインストールガイド](/imqa-guide/jpn/installation/android/mpm-sdk-install.md)により、IMQA agentコードを適用した後、この文書の内容を追加で適用してください
{% endhint %}

## 1. Podfileの追加

プロジェクトのPodfileに以下のように作成します。

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

## 2. PPHybridViewControllerの変更

viewWillAppearコードと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(@"誤ったjavascriptのリクエストです。");
    }
}
```

{% endcode %}

## \* Webview Agentの登録

Morpheusはサーバーからモバイルページを読み込む方式ではなく、モバイル内部にstaticファイルを置く方式です。ご提供するMorpheus用webview agentをすべてのページにおいてheadの一番上に位置するようにします。Morpheusの構造上、cdnを使用せず、直接リソースを挿入してください。


---

# 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/jpn/installation/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.
