본문으로 바로가기
Back to 플러그인
@capgo/capacitor-notifications
튜토리얼
@capgo/capacitor-notifications

通知

Capgo에서 사용자 조회, 배지, 통계, 및 침묵 업데이트 확인을 포함하여 네이티브 iOS 및 Android 푸시 알림을 보냅니다.

__CAPGO_KEEP_2__

__CAPGO_KEEP_3__ on Notifications

Using @capgo/capacitor-__CAPGO_KEEP_3__

Capgo의 native iOS 및 Android push notifications을 __CAPGO_KEEP_4__ lookup, __CAPGO_KEEP_5__, foreground/open tracking, __CAPGO_KEEP_6__ callbacks, 및 silent Capgo live-update checks를 통해 전송합니다.

Capgo notification pipeline을 위한 플러그인은 Cloudflare에 구축되었습니다. Capgo은 플랫폼 인증서 메타데이터 및 캠페인 제어 데이터를 Postgres에 저장하며, 활성 장치 상태 및 전달 이벤트는 Cloudflare Analytics Engine에 기록됩니다.

설치

이 패키지는 현재 비공개 프리뷰 상태입니다. Capgo은 패키지 접근 권한을 활성화하여 npm 계정에 설치를 위해 필요합니다.

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 설정

활성화 푸시 알림배경 모드 > Remote notifications in 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__ 폴더에 있는 capacitor.config.*.
  • 외부 고객 ID로 Capgo 에서 수신자를 검색하세요.
  • 디바이스가 플랫폼을 __CAPGO_KEEP_0__ 에서 확인하고, __CAPGO_KEEP_0__ 에서 권한이 부여되어야 합니다. android 또는 ios 그리고
  • 임시 리스너를 추가하세요. registrationChanged, notificationReceived, notificationOpenedbackgroundNotification.
  • 대시보드에서 테스트 알림을 보내세요.
  • 대기 중인, 전송된, 수신된, 열린 이벤트의 통계를 확인하세요.
  • silent 업데이트 확인을 위해 @capgo/capacitor-updater 설치되어야 합니다. autoUpdater 활성화되어야 합니다.

전체 참조

Using @capgo/capacitor-notifications에서 계속하세요.

If you are using @capgo/capacitor-notifications 을 사용하여 @capgo/capacitor-notifications 를 연결하세요. 구현 세부 사항은 Debugging 을 사용하여 @capgo/capacitor-updater 를 사용하여 @Capgo Plugin Directory 를 사용하여 다른 네이티브 플러그인을 사용하세요.