# iOS

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

## 1. 共通

### MPM Module install&#x20;

React native環境においてIMQA SDKを適用するために、下記のコマンドでパッケージをインストールする必要があります。.&#x20;

{% code title="npmコマンドを使う時" %}

```
 npm install imqa-react-native-agent --save
 npx pod-install
```

{% endcode %}

{% code title="yarnコマンドを使う時" %}

```
 yarn add imqa-react-native-agent
 npx pod-install
```

{% endcode %}

## 2. プロジェクト設定&#x20;

1\. ImqaSettings.hファイルを作成した後、以下の内容を入力します。

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

NS_ASSUME_NONNULL_BEGIN
@interface ImqaSetting : NSObject
- (void) IMQASetting;
@end
NS_ASSUME_NONNULL_END
```

2\. ImqaSettings.mファイルを作成した後、以下の内容を入力します。

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

@implementation ImqaSetting
- (void) IMQASetting{
  
  if (([NSUserDefaults.standardUserDefaults objectForKey:@"serverUrl"] == nil)) {
    [NSUserDefaults.standardUserDefaults setObject:@"https://collector.imqa.io" forKey: @"serverUrl"];
  }
  
  if (([NSUserDefaults.standardUserDefaults objectForKey:@"projectKey"] == nil)) {
    [NSUserDefaults.standardUserDefaults setObject:@"" forKey: @"projectKey"];
  }
  
  NSString* PROJECT_KEY = [NSUserDefaults.standardUserDefaults objectForKey:@"projectKey"];
  NSString* API_URL = [NSUserDefaults.standardUserDefaults objectForKey:@"serverUrl"];
  NSLog(@"[IMQA] setAgentConfig : %@ %@", PROJECT_KEY, API_URL);
  IMQAConfig* mpmConfig = [[IMQAConfig alloc] init:PROJECT_KEY];
  mpmConfig.api_url = API_URL;
  [[IMQAMpm sharedInstance] runWithConfig:mpmConfig];
}
@end
```

3\. AppDelegate.hファイルから以下のいずれかをインポートしてください。

```
#import "ImqaSetting.h"
```

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

```
ImqaSetting* is = [ImqaSetting new];
[is IMQASetting];
```

## 3. 詳細設定

iOS MPMフレームワークには、様々な設定を提供しています。

### 収集周期設定

IMQA MPMフレームワークがデータを保存する周期と収集する周期を秒単位で設定することができます。

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

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

```objectivec
IMQAConfig* mpmConfig = [[IMQAConfig alloc] init:@"PROJECT_KEY"];
mpmConfig.dump_interval = 10; // Interval of getting the performance data dump (sec)
mpmConfig.save_interval = 60; // Interval of sending performance data to the collection server (sec)
```

{% endcode %}

### ネットワーク収集設定&#x20;

IMQA MPMフレームワークでは、ネットワーク収集に対する収集の有無を設定することができます。また、特定のURLに対する収集を無視できる機能を提供しているため、セキュリティが要求されるURLを無視することができます。

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

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

```objectivec
IMQAConfig* mpmConfig = [[IMQAConfig alloc] init:@"PROJECT_KEY"];
mpmConfig.useNetworkCollect = YES; //YES: Collect, NO: Do not collect
mpmConfig.ignoreUrl = @[@"https://url1.com", @"http://url.com"]; // An array of specific URLs to ignore
```

{% endcode %}

### 収集データ確認&#x20;

IMQA MPMフレームワークで収集しているデータを確認したい場合は、オプションを通してデータをConsoleで確認することができます。

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

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

```objectivec
IMQAConfig* mpmConfig = [[IMQAConfig alloc] init:@"PROJECT_KEY"];
mpmConfig.downloadDumpData = YES;
```

{% endcode %}

## 4. ネットワーク収集(NSURLSessionまたはURLSessionを使用する場合)

NSURLSessionまたはURLSessionでネットワークを通信する場合、一部の状況でネットワーク収集のための設定が必要です。

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

```objectivec
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration ephemeralSessionConfiguration]; // or default
configuration.protocolClasses = [[IMQAMpm sharedInstance] imqaURLSessionProtocol];
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration];
```

## 5. dSYM設定

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


---

# 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/react-native/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.
