Python进行iOS推送(APNS)

2019-11-22  本文已影响0人  冷煖自知

Python服务端

下载PyAPNs
安装python setup.py install

Python文件

import os
from apns import APNs, Frame, Payload

apn = APNs(use_sandbox=True, cert_file=os.path.join('', 'apns-dev-cert.pem'), key_file=os.path.join('', 'dev-key-noec.pem'))

token_hex = '<Your DeviceToken>'
payload = Payload(alert="Hello World!", sound="default", badge=1)
apn.gateway_server.send_notification(token_hex, payload)

Swift DeviceToken获取

// 注册远程通知
UIApplication.shared.registerForRemoteNotifications()
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        var deviceTokenString = String()
        let bytes = [UInt8](deviceToken)
        for item in bytes {
            deviceTokenString += String(format:"%02x", item&0x000000FF)
        }
        print("deviceToken:\(deviceTokenString)")
        
    }

关于推送证书pem生成

上一篇下一篇

猜你喜欢

热点阅读