コンテンツにジャンプ

Getting Started

GitHub

@capgo/capacitor-notifications Capgoは、ネイティブiOSおよびAndroidプッシュ通知の第一パーティーCapgoプラグインです。Capgoのダッシュボード、パブリックAPI、分析エンジン、デバイスレジストリ、キャンペーン統計、バッジの更新、静的なライブアップデートチェックに構築されています。

パッケージは現在プライベートプレビュー中です。Capgoは、npmアカウントのパッケージアクセスを有効にする必要があります。インストールコマンドが機能するためには。

  • CapacitorアプリがすでにCapgoに追加されている場合。
  • Capgoアプリの通知タブへのアクセス
  • CapgoのAPIキーがバックエンドの証明印刷とAPI送信のために書き込みアクセス権を持っている場合。
  • アプリのiOSおよび/またはAndroidプラットフォームプッシュ権限
  • @capgo/capacitor-updater 静的なプッシュアップデートチェックを行う場合

Capgoでアプリを開き、次に 通知.

各プラットフォームをサポートするために1つのプラットフォームクレデンシャルエントリを追加します:

  • Android - アプリパッケージIDとAndroidプッシュプロジェクトメタデータ。
  • iOS - バンドルID、チームID、キーID、およびiOSプッシュキーと一致するメタデータ。

Capgoは、プラットフォームが設定済みとマークされる前に、APIワーカー内に存在する必要がある環境シークレット名を示しています。ダッシュボードはメタデータと期待されるシークレット参照を保存します。プライベートクレデンシャルはワーカー環境内に残ります。

最速のセットアップのために、以下のコマンドを実行してください: Capgo CLI

ターミナルウィンドウ
npx @capgo/cli@latest notifications setup com.example.app

Capacitor コマンドを実行すると、通知パッケージがインストールされ、Capacitor プラグインの設定が保存され、ヘルパーファイルが作成され、Capacitor 同期が実行されます。新しいアプリケーションに使用するパスは、このパスを使用します。必要に応じて、すべてのファイルを手動で接続する必要がある場合を除き。

手動インストール:

ターミナルウィンドウ
npm install @capgo/capacitor-notifications @capgo/capacitor-updater
npx cap sync

Capgo の静音アップデートチェックを使用していない場合、次のステップを省略できます。 @capgo/capacitor-updater.

3. プラグインの設定

セクション

アプリケーションが起動したときに一度だけプラグインを設定します。

import { CapgoNotifications } from '@capgo/capacitor-notifications'
await CapgoNotifications.configure({
appId: 'com.example.app',
autoUpdater: true,
updateInstallMode: 'next',
})

使用 updateInstallMode: 'next' To __CAPGO_KEEP_0__ をダウンロードして、再起動またはバックグラウンドサイクル後にインストールします。使用するには updateInstallMode: 'set' Capgo の更新を Capgo ができるだけ安全に実行できる時点で即時インストールしたい場合にのみ使用してください。

4. ID証明書を発行する

「4. ID証明書を発行する」

Capgo の Capgo API キーをモバイルアプリに置かないでください。バックエンドは、ユーザー認証が成功したあとに Capgo から ID証明書を取得するようにしてください。 identityProof ターミナルウィンドウ

コピー
curl -X POST 'https://api.capgo.app/notifications/recipients/proof' \
-H 'Content-Type: application/json' \
-H 'x-api-key: CAPGO_API_KEY' \
-d '{
"appId": "com.example.app",
"externalId": "customer-user-123"
}'

アプリに戻します。 identityProof 5. デバイスを登録する

「5. デバイスを登録する」

Copy to clipboard

サインインしている顧客ユーザーがわかっている場合にのみ登録します。

const registration = await CapgoNotifications.register({
externalId: 'customer-user-123',
identityProof,
tags: ['paid', 'beta'],
attributes: {
plan: 'team',
locale: 'en-US',
},
consent: true,
})
console.log(registration.recipientKey, registration.deviceKey)

Call register 次の場合に再度呼び出してください:

  • アプリが起動したとき。
  • ネイティブ プッシュ トークンが変更されたとき。
  • サインインしているユーザーが変更されたとき。
  • タグ、属性、または同意が変更されたとき。
  • 長い間アプリの登録を更新していない場合。

アプリ起動時にリスナーを登録して、JavaScriptでフォアグラウンド、オープン、バックグラウンド イベントを表示します。

await CapgoNotifications.addListener('registrationChanged', () => {
void CapgoNotifications.register({
externalId: currentUser.id,
identityProof: currentUser.capgoNotificationProof,
tags: currentUser.notificationTags,
consent: currentUser.pushConsent,
})
})
await CapgoNotifications.addListener('notificationReceived', (notification) => {
console.log('Notification received', notification)
})
await CapgoNotifications.addListener('notificationOpened', (event) => {
console.log('Notification opened', event.notification.id)
})
await CapgoNotifications.addListener('backgroundNotification', async (event) => {
try {
console.log('Background notification', event.notification.data)
} finally {
await event.finish()
}
})

常に呼び出す finish() 作業が完了した後、バックグラウンド通知のために呼び出す。作業は短く、idempotentでなければなりません。

Xcodeでアプリのターゲットを開き、有効にする:

  • Push通知
  • バックグラウンドモード > Remote通知

Remote通知を ios/App/App/AppDelegate.swift:

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
NotificationCenter.default.post(name: Notification.Name("CapgoNotificationsRemoteNotification"), object: userInfo)
completionHandler(.newData)
}

次に実行する:

ターミナルウィンドウ
npx cap sync ios

iOSデバイスを使用してバックグラウンド通知をテストすることをお勧めします。シミュレータはUIの作業に便利ですが、生産的なバックグラウンドプッシュの動作を表すものではありません。

実行:

ターミナルウィンドウ
npx cap sync android

次に、確認してください:

  • CapgoにAndroidプラットフォームの資格情報が設定されています。
  • アプリのパッケージIDは、プラットフォームプッシュの設定で使用されているパッケージIDと一致しています。
  • Android 13以降の通知許可を求める前に、表示される通知を期待してください。
  • アプリには、ブランドに合った通知アイコンとチャンネル戦略が設定されています。
  • Google Play servicesを使用した物理デバイスまたはエミュレータでテストします。

アプリ起動時にデフォルトのAndroidチャネルを作成します:

await CapgoNotifications.configure({ appId: 'com.example.app' })
await CapgoNotifications.register({
externalId: currentUser.id,
identityProof: currentUser.capgoNotificationProof,
consent: true,
})

Androidプッシュメッセージングサービスを宣言するプラグインです。ホストアプリのバックアップ、データ抽出、ネットワークセキュリティ、通知アイコンポリシーを保持します。

使用 通知 > テスト送信 Capgoにコピーする、またはAPIのパブリックメソッドをバックエンドから呼び出してください:

ターミナルウィンドウ
curl -X POST 'https://api.capgo.app/notifications/send' \
-H 'Content-Type: application/json' \
-H 'x-api-key: CAPGO_API_KEY' \
-d '{
"appId": "com.example.app",
"target": { "externalId": "customer-user-123" },
"payload": {
"title": "Hello from Capgo",
"body": "This is a test notification.",
"data": { "screen": "inbox" }
}
}'

キャンペーンの場合、ダッシュボードで作成するか、__CAPGO_KEEP_1__のパブリックメソッドをバックエンドから呼び出してください: /notifications/campaigns外部ID、タグ、セグメント、またはブロードキャストアウディエンスに送信します。

await CapgoNotifications.setBadge(4)
await CapgoNotifications.incrementBadge()
await CapgoNotifications.clearBadge()

バックエンドから:

ターミナルウィンドウ
curl -X POST 'https://api.capgo.app/notifications/badge' \
-H 'Content-Type: application/json' \
-H 'x-api-key: CAPGO_API_KEY' \
-d '{
"appId": "com.example.app",
"target": { "externalId": "customer-user-123" },
"badge": 4
}'

11. 静音アップデートチェックを有効にする

セクション「11. 静音アップデートチェックを有効にする」

静音アップデートチェックはこのプラグインを @capgo/capacitor-updater.

アプリ内:

await CapgoNotifications.enableUpdaterIntegration({
enabled: true,
installMode: 'next',
})

Capgoで有効 ユーザーにアプリの更新をプッシュ in the app’s Notifications settings. Then send an update check from the dashboard or API:

__CAPGO_KEEP_0__またはターミナルウィンドウから
curl -X POST 'https://api.capgo.app/notifications/update-check' \
-H 'Content-Type: application/json' \
-H 'x-api-key: CAPGO_API_KEY' \
-d '{
"appId": "com.example.app",
"target": { "externalId": "customer-user-123" },
"installMode": "next"
}'

通知は静音で、再生IDを使用して繰り返し更新チェックを置き換えるため、プラットフォームが再生動作をサポートしている場合にのみ機能します。

  • 期待どおりの受信者検索でアプリがCapgoに表示される externalId.
  • __CAPGO_KEEP_0__の許可 granted またはユーザーが通知許可を受け入れている場合
  • 登録されたプラットフォームは__CAPGO_KEEP_0__ android または、トークン更新後、fires される。 ios.
  • registrationChanged バックグラウンドテストログ
  • フロントバックグラウンドテストログ notificationReceived.
  • ダッシュボードの統計は、送信待ちと送信済みのイベントを表示し、デバイスが報告したときに受信/開封される。 notificationOpened.
  • 静的更新チェックは、
  • またはアップデータ統合の結果をログします。 runUpdateCheck Getting Startedから続けてください

Getting Startedから続けてください

セットアップがうまくいかない場合は、

デバッグ アプリケーションを変更する前に、__CAPGO_KEEP_0__を確認してください。多くの失敗は、アイデンティティの証明の不一致、プラットフォームの資格情報のセットアップ、OSの許可状態、バックグラウンドのサスペンド、またはアプリ/パッケージIDの不一致によって引き起こされます。']} before changing app code. Most failures are caused by identity proof mismatch, platform credential setup, OS permission state, background throttling, or app/package ID mismatch.