Created
May 31, 2021 17:18
-
-
Save bergusman/3109444b4923522e8b9d5b43d3174933 to your computer and use it in GitHub Desktop.
APNs pushing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const uuidv4 = require('uuid').v4 | |
| const APN = require('./apn') | |
| const apn = new APN({ | |
| key: KEY, | |
| keyId: KEY_ID, | |
| teamId: TEAM_ID | |
| }) | |
| const apnsId = uuidv4() | |
| const collapseId = '2822ed3f-3c9e-4775-8058-a92540bbb0d3' | |
| const pushId = uuidv4() | |
| // JWT: https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/establishing_a_token-based_connection_to_apns | |
| // Request: https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns | |
| // Response: https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/handling_notification_responses_from_apns | |
| // Request & Response: https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html | |
| // Payload: https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/generating_a_remote_notification | |
| // Payload: https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html | |
| // Background: https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/pushing_background_updates_to_your_app | |
| apn.push(DEVICE_TOKEN, { | |
| 'apns-topic': BUNDLE_ID, | |
| 'apns-id': apnsId, | |
| 'apns-push-type': 'alert', | |
| 'apns-priority': '10', | |
| 'apns-collapse-id': collapseId, | |
| 'apns-expiration': Math.floor(Date.now() / 1000) + 3600 | |
| }, { | |
| 'aps': { | |
| //'content-available': 1, | |
| 'mutable-content': 1, | |
| 'thread-id': '1', | |
| //'category': 'MESSAGE_RESPONSE', | |
| 'alert': { | |
| 'title': 'Заголовок', | |
| 'subtitle': 'Подзаголовок', | |
| 'body': `Тело: ${new Date().toLocaleTimeString()}` | |
| }, | |
| 'badge' : 8, | |
| }, | |
| 'pushId': pushId, | |
| 'event': { | |
| 'kind': 'message', | |
| 'message': { | |
| 'id': 1337, | |
| 'text': 'Привет' | |
| } | |
| } | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment