# Crash SDK設定

## 1. 詳細設定

### 収集サーバー設定

{% hint style="warning" %}
インストール型で実行された顧客会社では、必ずこの設定をする必要があります。
{% endhint %}

IMQA Crashフレームワークが収集するデータを送る収集サーバーを別途に設定することができます。基本的に、SaaSサービスをご利用中の方は、別途に設定する必要がありません。<br>

**Objective-C設定方法**

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

```swift
NSString* imqaUrl = @"https://custom-url";
IMQACrashConfiguration* crashConfig = [[IMQACrashConfiguration alloc] initWithApiKey:PROJECT_KEY];

IMQACrashEndpointConfiguration* endpoint = [[IMQACrashEndpointConfiguration alloc] init];
endpoint.notify = [imqaUrl stringByAppendingString:@"/cocoa/crash/send"];
endpoint.sessions = [imqaUrl stringByAppendingString:@"/cocoa/session"];
crashConfig.endpoints = endpoint;


```

{% endcode %}

**Swift設定方法**

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

```swift
let imqaUrl = "https://custom-url"
let crashConfig = IMQACrashConfiguration("<PROJECT_KEY>")
crashConfig.endpoints = IMQACrashEndpointConfiguration(
                                 notify: imqaUrl + "/cocoa/crash/send",
                                 sessions: imqaUrl + "/cocoa/session")
```

{% endcode %}

## 2. カスタムエラー送信

IMQA Crashは、カスタムErrorを直接送信することができます。各種ネットワークエラーや収集したいErrorは、NSErrorを通して私たちのサーバーへ直接送り、トラッキングすることができます。

### **Objective-C**設定方法

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

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

NSError* custom_error = [NSError errorWithDomain:@"custom_error" code:404 userInfo:NULL];
[IMQACrash notifyError:custom_error];
```

{% endcode %}

### **Swift**設定方法

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

```swift
let custom_error = NSError(domain: "custom error", code: 404, userInfo: nil)
IMQACrash.notifyError(custom_error)
```

{% endcode %}

## 3. Custom Web Crash 発生

IMQA Webview Agentでは、詳細なWebエラー分析に必要なエラーメッセージを指定してカスタムエラーを収集できます。

{% hint style="warning" %}
Webview Crash 収集のためには CrashWebviewBridge を追加する必要があります。 「[Android > MPM SDK設定 >  WebView HTTPリクエスト >  Android Agent設定](/imqa-guide/jpn/installation/android/mpm-sdk-setting.md#android-agent)」を参照してください。
{% endhint %}

### カスタムエラーの生成

IMQA Crash は、ユーザーが定義したエラーを検出して収集します。

{% hint style="warning" %}
他のエラーであっても同じエラータイプの場合、同じエラーとして認識してエラーが蓄積することがあります。
{% endhint %}

### カスタムエラーメッセージの指定

WebViewが収集するデフォルトのエラーメッセージを目的のエラーメッセージに変更して収集できます。 詳細なWebエラー分析のためにエラーメッセージを指定することをお勧めします。

{% hint style="warning" %}
エラーメッセージを指定した場合、同じエラータイプであっても別のエラーとして収集されます。
{% endhint %}

{% code title="js files to collect custom errors" %}

```javascript
...
// When using try-catch
try {
	...
}
catch(e){
	throw new Error("Custom error messages");
}

// When to generate default errors
new Error("Custom error messages");
```

{% endcode %}

以下のように、IMQA Crash サービスで Web クラッシュを詳細な情報とともに確認できます。

<figure><img src="https://lh7-us.googleusercontent.com/CW4QD8o6NvrtFpAORvtdBUR8Cxbht1HyBEAsmolCEGG1hyJ13RrUbqbF7KWB62PqL0BPg5hFbHqFjRJYtOaS8E9PVRdiuwIT93NGZN53NRITlp5cVNOei4TgQP5SVOHkUBqVVjL99rlmKYS88hPiS30" alt=""><figcaption></figcaption></figure>

**❶ キャッチされたエラーインスタンス**\
Webビューでエラーが生成された場合は、そのエラーのキャッチされたエラーインスタンス名を表示します。

**❷ ユーザー定義のエラーメッセージ**\
特定のエラータイプのエラーが作成されるとき、ユーザーが指定したメッセージを表示します。

```javascript
throw new Error("Custom error messages");
```

**❸ エラータイプ / コードの行番号**\
Webビューエラーの種類と当該エラーの行番号を確認することができます。

<table><thead><tr><th width="179" align="center">Error Type</th><th align="center">Description</th></tr></thead><tbody><tr><td align="center">Error</td><td align="center">ユーザーが設定したエラータイプです。</td></tr><tr><td align="center">EvalError</td><td align="center"><mark style="color:red;">eval()</mark>で発生するエラーです。</td></tr><tr><td align="center">RangeError</td><td align="center">変数の有効な範囲を外れた場合に作成されるエラーです。</td></tr><tr><td align="center">ReferenceError</td><td align="center">誤った参照をした場合に作成されるエラーです。</td></tr><tr><td align="center">SyntaxError</td><td align="center">誤った構文がある場合のエラーです。</td></tr><tr><td align="center">TypeError</td><td align="center">有効なデータ型でない場合におけるタイプのエラーです。</td></tr><tr><td align="center">URIError</td><td align="center"><mark style="color:red;">encodeURI()</mark>や<mark style="color:red;">decodeURI()</mark>の関数に無効なパラメーターを渡した場合に作成されるエラーです。</td></tr><tr><td align="center">AggregateError</td><td align="center">複数のエラーを一つのエラーで包むエラータイプです。</td></tr></tbody></table>

## 4. dSYM設定

iOSのSymbolication（シンボル化）を適用したアプリの場合は、dSYM設定でクラス名と関数名を確認できます。 「IMQA MPMユーザーガイド> 2.4。 プロジェクト管理> dSYM設定」を参照してください。&#x20;


---

# 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/ios/crash-sdk-setting.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.
