> For the complete documentation index, see [llms.txt](https://app.developers.karte.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://app.developers.karte.io/ios-sdk-appendix/appendix-logout-ios-sdk.md).

# \[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連携](/ios-sdk/webview-ios-sdk.md) を行っている場合は、ビジターIDの再生成と合わせ、WebView上のCookie/localStorageについても削除が必要です。

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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://app.developers.karte.io/ios-sdk-appendix/appendix-logout-ios-sdk.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
