> For the complete documentation index, see [llms.txt](https://documentation.pushly.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://documentation.pushly.com/pushly-ja/integration/implementation-steps/apple-ios/sdk-swift-obj-c/sdkmesoddo.md).

# SDKメソッド

## 権限ダイアログを手動で起動する

プラットフォーム経由で権限ダイアログの自動起動を無効にすることもできます。この場合、独自の基準に基づいてダイアログを起動するようにします（例: 訪問者がモーダル / ソフトプロンプトとやり取りした後、特定の画面/ページを訪問した後など）。

以下のコードでダイアログを手動で起動できます:

{% tabs %}
{% tab title="Swift" %}

```swift
PushSDK.PushNotifications.showPermissionPrompt() { granted, settings, error in
    // 任意のコールバック
    print("User accepted permissions: \(granted)")
}
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
[PushSDKPushNotifications showPermissionPrompt:^(BOOL granted, UNNotificationSettings * _Nonnull settings, NSError * _Nullable error) {
    // 任意のコールバック
    NSLog(@"User accepted permissions: %d", granted);
}];
```

{% endtab %}
{% endtabs %}

## 購読者のプロフィールに属性を追加する

購読者のプロフィールに属性を追加し、後でそれらの属性に基づいてセグメント分けを行うことができます。たとえば、特定の種類のニュース（例: 政治、スポーツ）に興味がある訪問者にタグを付け、それらを特定の通知の対象にしたい場合があります。

{% tabs %}
{% tab title="Swift" %}

```swift
PushSDK.UserProfile.set(["politics", "news"], forKey: "interests")
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
[PushSDKUserProfile set:@YES forKey:@"is_paying_subscriber"];
```

{% endtab %}
{% endtabs %}

一度に複数の属性を設定したい場合は、値のマップを送信することもできます。次の例では、両方を設定します `is_paying_subscriber` および `interests` 購読者の属性。

{% tabs %}
{% tab title="Swift" %}

```swift
PushSDK.UserProfile.set([
  "is_paying_subscriber": true,
  "interests": ["politics", "news"]
])
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
[PushSDKUserProfile set:@{
    @"is_paying_subscriber": @YES,
    @"interests": @[@"politics", @"news"]
}];
```

{% endtab %}
{% endtabs %}

プロパティの値を配列として保存している場合は、 `append` および `remove` メソッドを使って値を追加または削除します:

{% tabs %}
{% tab title="Swift" %}

```swift
// 購読者の既存の興味に 'sports' を追加
PushSDK.UserProfile.append(["sports"], to: "interests")

// 購読者の興味から 'fashion' と 'news' を削除
PushSDK.UserProfile.remove(["fashion", "news"], from: "interests")
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
// 購読者の既存の興味に 'sports' を追加
[PushSDKUserProfile append:@[@"sports"] to:@"interests"];

// 購読者の興味から 'fashion' と 'news' を削除
[PushSDKUserProfile remove:@[@"fashion", @"news"] from:@"interests"];
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
以下を使うプロパティ `append` では、提供された最新の20個の値のみが保存されます。
{% endhint %}

## アクティビティの追跡（URL / 画面の訪問）

アプリケーション内での購読者の流れを追跡するには、アクティビティ追跡を使用できます。画面またはURL経由で追跡でき、必要に応じて関連するメタデータ/タグを渡せます。

この情報は、セグメンテーションで使用して、訪問回数や直近性に基づくタグ付きの特定のURLや画面を訪れた購読者のコホートを作成するために利用できます。例えば: 「過去30日間に少なくとも4回、"Astrology" とタグ付けされたページ/画面を訪れた購読者」.

{% tabs %}
{% tab title="Swift" %}
キーワード/タグのメタデータとともに、訪問したURLまたは画面を追跡するには:

```swift
PushSDK.UserProfile.trackActivity(name: "myapp://dashboard", withTags: ["my-tag"])
```

また、提供するタグがない場合は `tags` パラメータを省略します:

```swift
PushSDK.UserProfile.trackActivity(name: "https://www.pushly.com/article-1")
```

{% endtab %}

{% tab title="Objective-C" %}
キーワード/タグのメタデータとともに、訪問したURLまたは画面を追跡するには:

```objectivec
[PushSDKUserProfile trackActivityWithName:@"myapp://dashboard" withTags:@[@"my-tag"]];
```

また、提供するタグがない場合は `2回目` パラメータを省略します:

```objectivec
[PushSDKUserProfile trackActivityWithName:@"https://www.pushly.com/article-1"];
```

{% endtab %}
{% endtabs %}

## 匿名の Push ID を取得する

PushSDK は、イベント追跡とデバッグの目的で匿名の Push ID を自動的に割り当てます。

Push ID を返すには、以下のコードを実行してください:

{% tabs %}
{% tab title="Swift" %}

```swift
let pushId = PushSDK.UserProfile.anonymousId
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
NSString* pushId = PushSDKUserProfile.anonymousId;
```

{% endtab %}
{% endtabs %}

## 購読者の外部IDを設定する

購読者に一意のユーザーIDを提供すると、後で API を通じてその購読者とやり取りできるようになります。

購読者の外部IDが設定されたら、当社チームと連携して双方向の自動データ同期を構築できます。以下のユースケースは、パブリッシャーがサーバー間リクエストを通じて外部IDを使用する一般的な方法です。

* 個々の購読者にプログラムで通知を送信する
* 購読解除リクエストを処理する
* 購読者のプロフィール属性とイベントを追加および削除する

{% tabs %}
{% tab title="Swift" %}

```swift
PushSDK.UserProfile.externalId = "external-id"
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
PushSDKUserProfile.externalId = @"external-id";
```

{% endtab %}
{% endtabs %}

購読者にすでに External ID がタグ付けされているかどうかも確認できます:

{% tabs %}
{% tab title="Swift" %}

```swift
let currentExternalId = PushSDK.UserProfile.externalId
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
NSString* currentExternalId = PushSDKUserProfile.externalId;
```

{% endtab %}
{% endtabs %}

## 訪問者がすでに購読済みかどうかを判定する

ユーザーがすでに通知の購読者であるかどうかを知る必要がある場合は、次のスニペットを使用できます:

{% tabs %}
{% tab title="Swift" %}

```swift
let subscribed = PushSDK.PushNotifications.isSubscribed
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
BOOL subscribed = PushSDKPushNotifications.isSubscribed;
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
アプリケーションがユーザーの購読状態の変化に反応する必要がある場合は、次の実装を推奨します [権限ライフサイクルデリゲート](/pushly-ja/integration/implementation-steps/apple-ios/sdk-swift-obj-c/sdkderigto.md#permission-lifecycle-delegates) 変更があればすぐに通知を受け取れるようにするためです。
{% endhint %}

## 訪問者がプロンプト表示の対象かどうかを判定する

{% tabs %}
{% tab title="Swift" %}

```swift
let isEligible = PushSDK.PushNotifications.isEligibleToPrompt
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
BOOL isEligible = PushSDKPushNotifications.isEligibleToPrompt;
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
アプリケーションがユーザーの購読状態の変化に反応する必要がある場合は、次の実装を推奨します [権限ライフサイクルデリゲート](/pushly-ja/integration/implementation-steps/apple-ios/sdk-swift-obj-c/sdkderigto.md#permission-lifecycle-delegates) 変更があればすぐに通知を受け取れるようにするためです。
{% endhint %}

## ユーザー通知の一時停止 / 再開（ソフト購読解除）

次のメソッドを呼び出すことで、ユーザーの通知を一時停止できます:

{% tabs %}
{% tab title="Swift" %}

```swift
PushSDK.PushNotifications.pause()
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
[PushSDKPushNotifications pause];
```

{% endtab %}
{% endtabs %}

ユーザーの通知を再開する場合は、次のメソッドを呼び出します:

{% tabs %}
{% tab title="Swift" %}

```swift
PushSDK.PushNotifications.resume()
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
[PushSDKPushNotifications resume];
```

{% endtab %}
{% endtabs %}

ユーザーの通知が現在一時停止されているかを確認するには:

{% tabs %}
{% tab title="Swift" %}

```swift
PushSDK.PushNotifications.isPaused
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
BOOL isPaused = PushSDKPushNotifications.isPaused;
```

{% endtab %}
{% endtabs %}

## ユーザーを完全に削除する

ユーザーをすべての通知と追跡の対象から除外する必要がある場合は、次のメソッドを実行してください:

{% tabs %}
{% tab title="Swift" %}

```swift
PushSDK.UserProfile.requestUserDeletion()
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
[PushSDKUserProfile requestUserDeletion];
```

{% endtab %}
{% endtabs %}

## SDK のログレベルを設定する

PushSDK のログレベルは `none` がデフォルトに設定されています。サポートされるログレベルは次のとおりです: `verbose`, `debug`, `info`, `warn`, `error`, `critical`、および `none`.

{% tabs %}
{% tab title="Swift" %}

```swift
PushSDK.logLevel = .info
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
PushSDK.logLevel = PNLogLevelInfo
```

{% endtab %}
{% endtabs %}


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://documentation.pushly.com/pushly-ja/integration/implementation-steps/apple-ios/sdk-swift-obj-c/sdkmesoddo.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
