> For the complete documentation index, see [llms.txt](https://docs.imqa.io/imqa-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.imqa.io/imqa-guide/jpn/installation/cordova/ios.md).

# iOS

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

## 1. SDKのインストール

1\. \<PROJECT-NAME>.xcworkspaceファイルを開きます。

2\. iosフォルダの下にframeworksというフォルダを作成します。

3\. 下記のリンクから希望するバージョンのフレームワークをインストールしてXcode上に、frameworksフォルダにフレームワークファイルを移しながらCopy Items If neededをチェックします。

* <https://github.com/onycom-imqa/IMQA-MPM-Release/releases>
* <https://github.com/onycom-imqa/IMQA-Crash-Release/releases>&#x20;

4\. プロジェクト設定でFrameworks、Libraries、and Embedded ContentにおいてフレームワークをすべてEmbed & Signに設定します。

## 2. SDKの設定

1\.  AppDelegate.mファイルから以下の2つをインポートします。

{% code title="AppDelegate.m" %}

```
#import <IMQAMPMAgent/IMQAMPMAgent.h>
#import <IMQACrashAgent/IMQACrash.h>
```

{% endcode %}

2\.  AppDelegate.mファイルで- (BOOL)application:(UIApplication\*)application didFinishLaunchingWithOptions:(NSDictionary\*)launchOptions関数の一番上に下記のコードを追加します。

{% code title="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];
```

{% endcode %}

3\. ビルドの後に実行した時、下記のようなログが確認されたら正常にインストールが完了します。

{% code title="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>
```

{% endcode %}

## 3. Cordovaの設定

1\. HTMLの最上段にWebview Agentをインストールします。<mark style="color:red;">(インストールした後、ビルドは必須)</mark>

{% code title="index.html" %}

```html
<!-- IMQA Webview Agent(1.1.3バージョン以下)です。  -->
<script type="text/javascript" src="https://imqawebviewagent.blob.core.windows.net/agent/webview-agent-1.1.2.js"
crossorigin></script>

// minファイルを適用したい場合
<script type="text/javascript" src="https://imqawebviewagent.blob.core.windows.net/agent/webview-agent-1.1.2.min.js"
crossorigin></script>
```

{% endcode %}

{% code title="index.html" %}

```html
<!-- IMQA Webview Agent(1.1.3バージョン以上)です。  -->
<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エージェント実行関数
    })(window, 'imqaClientConfig', 'IMQAWebviewMain', 'IMQAWebMain', 'webkit', 'messageHandlers', 'ImqaBridge')
</script>
```

{% endcode %}

2\. XcodeにおいてCordovaLib/Private/Plugins/CDVWebViewEngine/CDVWebViewEngine.mファイルを探します。

3\. CDVWebViewEngine.mの上にMPM SDKをインポートします。

{% code title="CDVWebViewEngine.m" %}

```
#import <IMQAMPMAgent/IMQAMPMAgent.h>
```

{% endcode %}

4\.  - (void)pluginInitialize関数においてWKUserContentControllerを変更する部分を探して変更します。

{% code title="CDVWebViewEngine.m" %}

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

{% endcode %}

5\. - (void)userContentController:(WKUserContentController\*)userContentController didReceiveScriptMessage:(WKScriptMessage\*)message関数を探して変更します。

<mark style="color:red;">**\*\*\*必ずその関数の一番上に追加してください。\*\*\***</mark>

{% code title="CDVWebViewEngine.m" %}

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

{% endcode %}

\ <br>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.imqa.io/imqa-guide/jpn/installation/cordova/ios.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
