# \[iOS]オプトアウトに対応する

KARTE SDKによるユーザーの行動データ収集や各種アクションの配信（アプリ内メッセージ等）を無効にしたい場合はオプトアウト機能を利用してください。

オプトアウト時に制限される機能については[KARTE for App SDKのオプトアウト](https://support.karte.io/post/4QmpYqEwJplN2VeVBWGjZk#2-0)を御覧ください。

## 初期状態を設定する

Configurationクラスの `isOptOut` 値を設定することで、SDK初期化時点での初期状態を設定することが可能です。\
以下の例では、SDKの初期化時点ではオプトアウト状態となります。

{% tabs %}
{% tab title="Swift" %}
{% code title="AppDelegate.swift" overflow="wrap" %}

```swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
  let configuration = Configuration { (configuration) in
    configuration.isOptOut = true
  }
  KarteApp.setup(appKey: "アプリケーションキー", configuration: configuration)
  ...
}
```

{% endcode %}
{% endtab %}

{% tab title="Objective-C" %}
{% code title="AppDelegate.m" overflow="wrap" %}

```objc
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  KRTConfiguration *configuration = [KRTConfiguration configWithConfigurator:^(KRTConfiguration * _Nonnull configuration) {
    [configuration setIsOptOut:YES];
  }];
  [KRTApp setupWithAppKey:@"アプリケーションキー" configuration:configuration];
  ...
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

## オプトインする

`optIn` メソッドを呼び出すことで、オプトイン状態にすることが可能です。

{% tabs %}
{% tab title="Swift" %}
{% code overflow="wrap" %}

```swift
KarteApp.optIn()
```

{% endcode %}
{% endtab %}

{% tab title="Objective-C" %}
{% code overflow="wrap" %}

```objc
[KRTApp optIn];
```

{% endcode %}
{% endtab %}
{% endtabs %}

## オプトアウトする

`optOut` メソッドを呼び出すことで、オプトアウト状態にすることが可能です。

{% tabs %}
{% tab title="Swift" %}
{% code overflow="wrap" %}

```swift
KarteApp.optOut()
```

{% endcode %}
{% endtab %}

{% tab title="Objective-C" %}
{% code overflow="wrap" %}

```objc
[KRTApp optOut];
```

{% endcode %}
{% endtab %}
{% endtabs %}

{% hint style="info" %}
**optIn/optOut後の次回起動時の挙動について**

`optIn` および `optOut` メソッドを呼び出した場合、その情報は端末内に保存され、次回初期化時にも保存した設定に基づき動作します。
{% endhint %}


---

# 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://app.developers.karte.io/ios-sdk-appendix/appendix-optout-ios-sdk.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.
