yeonghoon.kim

  • 게시판
  • 갤러리
  • aws

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

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

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 985
공지 현금, 저축, 투자, 지출, 예산, 보험 내역(2024-05-30) 김영훈 2024.03.10 638
245 rocky linux 9 - init_script.sh 김영훈 2023.12.08 399
244 자바스크립트 화살표 함수 김영훈 2023.10.06 366
243 sar bash 스크립트 [1] 김영훈 2023.09.05 425
242 ELK Stack 테스트 [1] 김영훈 2023.08.30 322
241 CentOS7 php 7.4 + composer 설치 김영훈 2023.08.18 526
240 iptables ip 포워딩 [1] 김영훈 2023.08.17 309
239 삼성 스마트태그 배터리 - CR2032 김영훈 2023.08.15 279
238 geoip2 python [1] 김영훈 2023.08.10 331
» pyapns_client 동시에 여러 기기로 푸시 보내기 김영훈 2023.08.03 393
236 2학기 수강신청 김영훈 2023.08.01 297
235 let's encrypt 와일드카드 인증서 발급 (CentOS7) [2] 김영훈 2023.07.26 580
234 FCM 푸시보내기 - firebase_admin 김영훈 2023.07.20 300
233 FCM 푸시 보내기 - pyfcm 김영훈 2023.07.20 341
232 rockylinux kvm [1] 김영훈 2023.07.12 331
231 SAP_1. Identity & Federation Section 김영훈 2023.06.13 278
230 [Bard] node.js forever 사용법 알려줘 김영훈 2023.05.18 305
229 Sectigo PositiveSSL 신청 시 파일 - 20230512 기준 [1] file 김영훈 2023.05.12 333
228 데이터베이스 3주차 실습 김영훈 2023.03.19 341
227 python csv 파일 읽은 후 엑셀 파일로 저장 샘플 김영훈 2023.03.16 372
226 데이터베이스 2주차 - 실습 김영훈 2023.03.08 325
쓰기 태그
 첫 페이지 1 2 3 4 5 6 7 8 9 10 끝 페이지