Guide
__CAPGO_KEEP_0__の通知チュートリアル
capgoで@capgo/capacitor-notificationsを使用する
Capgoを使用して、iOSとAndroidのネイティブプッシュ通知を送信し、ユーザーロック、バッジ、フォアグラウンド/オープン追跡、バックグラウンドコールバック、静的Capgoライブアップデートチェックを実行します。
プラグインはCapgoの通知パイプラインに構築されています。CapgoはPostgresにプラットフォームクレデンシャルメタデータとキャンペーンコントロールデータを、Cloudflare Analytics Engineにアクティブデバイスの状態と配信イベントを記録します。
Install
このパッケージは現在プライベートプレビュー中です。Capgoがパッケージアクセスを有効にした後、npmアカウントのCapgoでインストールが機能します。
Capgo CLIを使用して、ガイデッドセットアップを実行します:
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',
})
署名ユーザーを登録
トークン発行 identityProof Capgoのバックエンドから 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 androidCapgo内でAndroidプラットフォームのクレデンシャルを設定し、Android 13以上で通知許可を要求し、Google Playサービスを搭載したデバイスまたはエミュレータでテストする。
デバッグチェックリスト
- 実行
npx @capgo/cli@latest notifications setup com.example.app__CAPGO_KEEP_0__内のフォルダからcapacitor.config.*. - Capgoで外部顧客IDで検索する受信者
- デバイスがプラットフォーム
androidまたはios許可が付与されていることを確認する - 一時的なリスナーを追加する
registrationChanged,notificationReceived,notificationOpened、とbackgroundNotification. - ダッシュボードからテスト通知を送信してください。
- キュー、送信、受信、開封イベントの統計を確認してください。
- 静的更新チェックの場合、
@capgo/capacitor-updaterインストールされているかどうかを確認してください。autoUpdater有効になっているかどうかを確認してください。
フルリファレンス
- ドキュメント: /docs/plugins/notifications/
- デバッグ: /docs/plugins/notifications/debugging/
- ソース: https://github.com/Cap-go/capgo/tree/main/packages/capacitor-notifications/
Using @capgo/capacitor-notificationsから続けてください。
If you are using @capgo/capacitor-notifications を使用して @capgo/capacitor-notifications の実装詳細については デバッグ for troubleshooting, @capgo/capacitor-updater for silent update checks, and Capgo プラグイン ディレクトリ for other native plugins.