# \[iOS]アプリケーションのログアウトに対応する

ログイン/ログアウト機能のあるアプリケーションでは、ログイン時に `identify` イベントで `user_id` を送信しユーザーをメンバー化します。\
このときSDKが自動生成する `visitor_id` と明示的に送信した `user_id` は紐付いた状態となります。

アプリケーション側でユーザーがログアウトを行った場合でもこの状態は維持されるため、アプリケーション上の状態と、KARTE側の状態が一致しない状態になってしまいます（アプリケーション側はビジター扱い、KARTE側はメンバー扱い）

**この状態を避けるために、ビジターIDを再生成する機能を利用することが可能です。**

## ビジターIDの再生成の方法

* ログアウト時に`renewVisitorId()`を実行することで再生成されます

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

```swift
KarteApp.renewVisitorId()
```

{% endcode %}
{% endtab %}

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

```objc
[KRTApp renewVisitorId];
```

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

## ビジターIDの再生成機能時に行われる処理

以下の処理が行われます。

* リセット対象のプッシュ通知の購読フラグ（plugin\_native\_app\_identity.subscribe）を `非購読（false）` に変更
* 端末に保存されている設定値の削除
* visitor\_id の再発行
* 新たに生成された visitor に対してFCMトークンを紐付け
  * 新たに生成されたvisitorでplugin\_native\_app\_identify.subscribeを再送信
* アプリビジターIDの再生成（native\_app\_renew\_visitor\_id）イベントを送信

## WebView利用時の注意事項

[WebView連携](https://app.developers.karte.io/ios-sdk/webview-ios-sdk) を行っている場合は、ビジターIDの再生成と合わせ、WebView上のCookie/localStorageについても削除が必要です。

削除が適切に行われない場合、ログアウト前の状態が意図せず継続する可能性があります。


---

# 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-logout-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.
