yeonghoon.kim

  • 게시판
  • 갤러리
  • aws

pyapns_client 동시에 여러 기기로 푸시 보내기

김영훈 2023.08.03 13:28 조회 수 : 401

from pyapns_client import APNSClient, IOSPayloadAlert, IOSPayload, IOSNotification, APNSDeviceException, APNSServerException, APNSProgrammingException, UnregisteredException

from concurrent.futures import ThreadPoolExecutor

import time

 

def send_notification(device_token):

    try:

        alert = IOSPayloadAlert(title='Title', body='Some message.')

        payload = IOSPayload(alert=alert,badge=1,sound='default')

        notification = IOSNotification(payload=payload, topic='topic')

 

        client.push(notification=notification, device_token=device_token)

        print(f'Successfully sent notification to {device_token}')

    except UnregisteredException as e:

        print(f'Device {device_token} is unregistered, compare timestamp {e.timestamp_datetime} and remove from db')

    except APNSDeviceException:

        print(f'Device {device_token} is potentially invalid, flag and remove from db after a few tries')

    except APNSServerException:

        print(f'Device {device_token}: try again later')

    except APNSProgrammingException:

        print(f'Device {device_token}: check your code and try again later')

 

# Your device tokens list

device_tokens = ['device_token1', 'device_token2']

 

# Initialize the APNS client

client = APNSClient(mode=APNSClient.MODE_DEV, root_cert_path=None, auth_key_path='auth_key', auth_key_id='auth_key_id', team_id='team_id')

 

start_time = time.time()

try:

    with ThreadPoolExecutor(max_workers=4) as executor:  # You can adjust the number of workers as needed

        executor.map(send_notification, device_tokens)

finally:

    client.close()

end_time = time.time()

 

print (end_time - start_time)


  • 추천 0

  • 비추천 0
이 게시물을
목록

댓글 0

사진 및 파일 첨부

여기에 파일을 끌어 놓거나 왼쪽의 버튼을 클릭하세요.

파일 용량 제한 : 0MB (허용 확장자 : *.*)

업로드 중... (0%)

0개 첨부 됨 ( / )
 
번호 제목 글쓴이 날짜 조회 수
공지 2025 일본 여행 계획 김영훈 2024.10.10 1108
공지 현금, 저축, 투자, 지출, 예산, 보험 내역(2024-05-30) 김영훈 2024.03.10 765
45 파이썬 디스크 용량 체크 김영훈 2023.01.04 468
44 paramiko 일괄 명령 테스트 김영훈 2023.01.05 342
43 아이맥 화면 동영상 캡처 - 커맨드 + 쉬프트 + 5 김영훈 2023.02.28 245
42 Python cx_Oracle 모듈 샘플코드 김영훈 2023.03.03 348
41 시스템프로그래밍 2주차 - 사용명령 김영훈 2023.03.08 294
40 데이터베이스 2주차 - 실습 김영훈 2023.03.08 332
39 python csv 파일 읽은 후 엑셀 파일로 저장 샘플 김영훈 2023.03.16 380
38 데이터베이스 3주차 실습 김영훈 2023.03.19 345
37 Sectigo PositiveSSL 신청 시 파일 - 20230512 기준 [1] file 김영훈 2023.05.12 337
36 [Bard] node.js forever 사용법 알려줘 김영훈 2023.05.18 317
35 SAP_1. Identity & Federation Section 김영훈 2023.06.13 283
34 rockylinux kvm [1] 김영훈 2023.07.12 342
33 FCM 푸시 보내기 - pyfcm 김영훈 2023.07.20 355
32 FCM 푸시보내기 - firebase_admin 김영훈 2023.07.20 311
31 let's encrypt 와일드카드 인증서 발급 (CentOS7) [2] 김영훈 2023.07.26 590
30 2학기 수강신청 김영훈 2023.08.01 304
» pyapns_client 동시에 여러 기기로 푸시 보내기 김영훈 2023.08.03 401
28 geoip2 python [1] 김영훈 2023.08.10 343
27 삼성 스마트태그 배터리 - CR2032 김영훈 2023.08.15 286
26 iptables ip 포워딩 [1] 김영훈 2023.08.17 318
쓰기 태그
 첫 페이지 5 6 7 8 9 10 11 12 13 14 끝 페이지