メインコンテンツにスキップ
プラグインに戻る
@capgo/capacitor-notifications
チュートリアル
@capgo/capacitor-notifications

通知

CapgoからiOSおよびAndroidのネイティブプッシュ通知を送信する

ガイド

通知のチュートリアル

Using @capgo/capacitor-notifications

Send native iOS and Android push notifications from Capgo with user lookup, badges, foreground/open tracking, background callbacks, and silent Capgo live-update checks.

The plugin is built for the Capgo notification pipeline. Capgo stores platform credential metadata and campaign control data in Postgres, while active device state and delivery events are written to Cloudflare Analytics Engine.

インストール

Use the Capgo CLI for a guided setup:

npx @capgo/cli@latest notifications setup com.example.app

手動インストール:

npm install @capgo/capacitor-notifications @capgo/capacitor-updater
npx cap sync

設定

import { CapgoNotifications } from '@capgo/capacitor-notifications'

await CapgoNotifications.configure({
  appId: 'com.example.app',
  autoUpdater: true,
  updateInstallMode: 'next',
})

ユーザーを署名登録

Mint identityProof バックエンドから POST /notifications/recipients/proof署名登録した後、デバイスを登録してください。

await CapgoNotifications.register({
  externalId: 'customer-user-123',
  identityProof,
  tags: ['paid'],
  attributes: { plan: 'team' },
  consent: true,
})

イベントをリスン

await CapgoNotifications.addListener('notificationReceived', (notification) => {
  console.log('Received', notification)
})

await CapgoNotifications.addListener('notificationOpened', (event) => {
  console.log('Opened', event.notification.id)
})

await CapgoNotifications.addListener('backgroundNotification', async (event) => {
  try {
    console.log('Background payload', event.notification.data)
  } finally {
    await event.finish()
  }
})

iOS設定

有効 プッシュ通知バックグラウンドモード > Remote notifications Xcodeで

リモート通知を転送 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)
}

Android セットアップ

実行 npx cap sync androidAndroid プラットフォームの資格情報を Capgo に設定し、Android 13 以降で通知許可を要求し、Google Play サービスを備えたデバイスまたはエミュレータでテストしてください。

デバッグ チェックリスト

  • 実行 npx @capgo/cli@latest notifications setup com.example.app __CAPGO_KEEP_0__ 内の受信者を外部顧客 ID で検索します。 capacitor.config.*.
  • Search the recipient in Capgo by external customer ID.
  • または android デバイスがプラットフォームを確認していることを確認します。 ios または
  • 一時リスナーを追加します。 registrationChanged, notificationReceived, notificationOpenedbackgroundNotification.
  • ダッシュボードからテスト通知を送信します。
  • キュー、送信、受信、開封イベントの統計を確認します。
  • 静的な更新チェックの場合、 @capgo/capacitor-updater インストールされているかどうかを確認し、 autoUpdater 有効になっているかどうかを確認します。

フル リファレンス

Keep going from Using @capgo/capacitor-notifications

Capacitor-notificationsを使用している場合 Using @capgo/capacitor-notifications __CAPGO_KEEP_0__/__CAPGO_KEEP_1__-通知 capgo/capacitor-通知 __CAPGO_KEEP_0__/__CAPGO_KEEP_1__-通知の実装詳細 デバッグ トラブルシューティング @capgo/capacitor-updater __CAPGO_KEEP_0__ プラグインディレクトリ Capgo Plugin Directory フッター