가이드
Capacitor에서 Notifications 사용법
@capgo/capacitor-notifications 사용하기
Capgo에서 사용자 조회, 배지, 포그라운드/오픈 추적, 백그라운드 콜백, 사일런트 Capgo 라이브 업데이트 체크를 통해 네이티브 iOS 및 Android 푸시 알림을 보내세요.
이 플러그인은 Capgo 알림 파이프라인을 위해 구축되었습니다. Capgo은 플랫폼 자격 증명 메타데이터와 캠페인 제어 데이터를 Postgres에 저장하고, 활성 디바이스 상태와 전달 이벤트는 Cloudflare Analytics Engine에 기록됩니다.
설치
가이드 설정에는 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 백엔드에서 다음을 사용하여 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 설정
활성화 푸시 알림 및 Background Modes > 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 android, Capgo에서 Android 플랫폼 인증 정보를 설정하고, Android 13+에서 알림 권한을 요청한 뒤, Google Play services가 포함된 기기나 에뮬레이터에서 테스트하세요.
디버깅 체크리스트
- 실행
npx @capgo/cli@latest notifications setup com.example.app다음이 포함된 폴더에서capacitor.config.*. - Capgo에서 외부 고객 ID로 수신자를 검색하세요.
- 기기에 플랫폼이 있는지 확인하세요
android또는ios권한이 허용된 상태입니다. - 임시 리스너 추가:
registrationChanged,notificationReceived,notificationOpened, 그리고backgroundNotification. - 대시보드에서 테스트 알림을 보내세요.
- 대기, 전송, 수신 및 오픈 이벤트 통계를 확인하세요.
- silent update 체크를 위해 다음을 확인하세요:
@capgo/capacitor-updater가 설치되어 있는지,autoUpdater부분 전사 업데이트를 수신합니다.
전체 레퍼런스
- 문서: /docs/plugins/notifications/
- 디버깅: /docs/plugins/notifications/debugging/
- 출처: https://github.com/Cap-go/capgo/tree/main/packages/capacitor-notifications/
@capgo/capacitor-notifications 사용 후 계속 진행하기
사용 중이라면 @capgo/capacitor-notifications 사용하기 네이티브 푸시 메시징을 계획하고, 다음과 연결하세요 @capgo/capacitor-notifications 구현 세부 사항은 디버깅 문제 해결은 @capgo/capacitor-updater 무음 업데이트 확인은, 그리고 Capgo 플러그인 디렉토리 다른 native plugin용입니다.