ガイド
Capacitorで使用する方法の通知
@capgo/capacitor-notificationsを使用する
Capgoから、ユーザー検索、バッジ、フォアグラウンド/オープン追跡、バックグラウンドコールバック、静的Capgoライブアップデートチェックを含むネイティブiOSおよびAndroidプッシュ通知を送信できます。
プラグインはCapgoの通知パイプラインに設計されています。CapgoはPostgresにプラットフォーム認証情報メタデータとキャンペーンコントロールデータを格納し、Cloudflareアナリティクスエンジンにアクティブデバイス状態と配信イベントを書き込んでいます。
インストール
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',
})
署名ユーザーを登録する
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通知 Xcodeで。
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)
}
Androidセットアップ
実行 npx cap sync androidAndroidプラットフォームの資格情報をCapgoに設定し、Android 13以降で通知許可を要求し、Google Playサービスを搭載したデバイスまたはエミュレータでテストしてください。
CapgoのUIを比較すると、ビルドステップでは、
- 実行
npx @capgo/cli@latest notifications setup com.example.appCapgoのUIを比較すると、インストールステップでは、capacitor.config.*. - 受信者を検索するには、外部顧客IDでCapgoを検索してください。
- デバッグチェックリスト
androidoriosおよび、許可が与えられている。 - 一時的なリスナーを追加します。
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
あなたが使用している Using @capgo/capacitor-notifications native push メッセージングの計画に使用している場合 @capgo/capacitor-notifications 実装の詳細 デバッグ トラブルシューティング @capgo/capacitor-アップデーター 静的更新チェックのために Capgo プラグインディレクトリ 他のネイティブ プラグインについて。