# 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 파일을 생성 후 아래 내용을 입력합니다.&#x20;

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

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

2\. ImqaSettings.m 파일을 생성 후 아래 내용을 입력합니다.&#x20;

```
#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 파일에서 아래 1개를 임포트하세요.

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

4\. AppDelegate.m 파일에서 - (BOOL)application:(UIApplication\*)application didFinishLaunchingWithOptions:(NSDictionary\*)launchOptions 함수 가장 상단에 아래 코드를 추가합니다.

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

## 3. 상세 설정

iOS MPM 프레임워크에는 다양한 설정을 지원하고 있습니다.&#x20;

### 수집 주기 설정

IMQA MPM 프레임워크가 데이터를 저장하는 주기와 수집하는 주기에 대해서 초 단위로 설정할 수 있습니다.&#x20;

* Objective-C 설정 방법

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

```objectivec
IMQAConfig* mpmConfig = [[IMQAConfig alloc] init:@"PROJECT_KEY"];
mpmConfig.dump_interval = 10; // 성능 데이터 덤프를 뜨는 주기 (sec)
mpmConfig.save_interval = 60; // 성능 데이터를 수집서버로 전송하는 주기 (sec)
```

{% endcode %}

### 네트워크 수집 설정&#x20;

IMQA MPM 프레임워크에서는 네트워크 수집에 대해서 수집 여부를 설정 할 수 있습니다. 또한, 특정 URL 에 대한 수집을 무시할 수 있는 기능을 제공하고 있어, 보안이 필요한 URL은 무시 할 수 있습니다.&#x20;

* Objective-C 설정 방법

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

```objectivec
IMQAConfig* mpmConfig = [[IMQAConfig alloc] init:@"PROJECT_KEY"];
mpmConfig.useNetworkCollect = YES; // YES: 수집함, NO: 수집안함
mpmConfig.ignoreUrl = @[@"https://url1.com", @"http://url.com"]; // 특정 URL 무시 Array
```

{% endcode %}

### 수집 데이터 확인&#x20;

IMQA MPM 프레임워크에서 수집하고 있는 데이터가 궁금한 경우 자체 옵션을 통해서 데이터를 Console 로 확인 하실 수 있습니다.&#x20;

* 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 설정

&#x20;iOS의 Symbolication(기호화) 적용이 된 앱의 경우, dSYM 설정을 통해 클래스 명과 함수 명을 확인할 수 있습니다. ‘[iOS > MPM 설정 > dSYM 설정](https://docs.imqa.io/imqa-guide/installation/react-native/pages/YQNEh40zjuQjmGBmfz57#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/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.
