Android
import firebase_admin
from firebase_admin import credentials, messaging
# Firebase 프로젝트의 서비스 계정 키 파일로 Firebase Admin 초기화
cred = credentials.Certificate('path/to/fcm-signkey.json')
firebase_admin.initialize_app(cred)
# 메시지 정의
message = messaging.Message(
data={
'score': '850',
'time': '2:45',
},
notification=messaging.Notification(
title='Match update',
body='Arsenal vs Chelsea',
),
android=messaging.AndroidConfig(
priority='high', # 우선순위 설정: 'high' 또는 'normal'
notification=messaging.AndroidNotification(
icon='stock_ticker_update',
color='#f45342'
),
),
token='recipient_device_token',
)
# 메시지 보내기
response = messaging.send(message)
print('Successfully sent message:', response)
iOS
import firebase_admin
from firebase_admin import credentials, messaging
# Firebase 초기화
if not firebase_admin._apps:
cred = credentials.Certificate('path/to/your/fcm-signkey.json')
firebase_admin.initialize_app(cred)
# APNs 설정을 포함한 메시지 정의
message = messaging.Message(
notification=messaging.Notification(
title='Match update',
body='Arsenal vs Chelsea',
),
apns=messaging.APNSConfig(
headers={
'apns-priority': '10', # '10'은 즉시 배달, '5'는 전력 효율적 배달
},
payload=messaging.APNSPayload(
aps=messaging.Aps(
alert=messaging.ApsAlert(
title='Match update',
body='Arsenal vs Chelsea',
),
sound='default',
),
),
),
token='recipient_device_token',
)
# 메시지 보내기
response = messaging.send(message)
print('Successfully sent message:', response)
'기타' 카테고리의 다른 글
iOS, Android 별 Foreground, Background 푸시 알림 알아보기 (0) | 2024.02.07 |
---|---|
AWS SNS를 이용한 Topic 기반 Push Notification (1) | 2024.01.30 |
모바일앱과 Spring boot 백엔드 연동을 통한 소셜로그인 구현 (0) | 2023.12.28 |
mapStruct 의존성 순서 문제 해결방법과 간단한 사용법 (0) | 2023.12.11 |
Spring에서 DTO 생성 시 Primitive Type과 Reference Type 중 어떤 것을 쓰는게 좋을까? (0) | 2023.12.10 |
댓글