You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+21-11Lines changed: 21 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -59,7 +59,7 @@ var options = {
59
59
production:false
60
60
};
61
61
62
-
var apnProvider =newapn.Provider(options);
62
+
constapnProvider=newapn.Provider(options);
63
63
```
64
64
65
65
By default, the provider will connect to the sandbox unless the environment variable `NODE_ENV=production` is set.
@@ -68,6 +68,10 @@ For more information about configuration options consult the [provider documenta
68
68
69
69
Help with preparing the key and certificate files for connection can be found in the [wiki][certificateWiki]
70
70
71
+
⚠️ You should only create one `Provider` per-process for each certificate/key pair you have. You do not need to create a new `Provider` for each notification. If you are only sending notifications to one app then there is no need for more than one `Provider`.
72
+
73
+
If you are constantly creating `Provider` instances in your app, make sure to call `Provider.shutdown()` when you are done with each provider to release its resources and memory.
74
+
71
75
### Connecting through an HTTP proxy
72
76
73
77
If you need to connect through an HTTP proxy, you simply need to provide the `proxy: {host, port}` option when creating the provider. For example:
@@ -86,7 +90,7 @@ var options = {
86
90
production:false
87
91
};
88
92
89
-
var apnProvider =newapn.Provider(options);
93
+
constapnProvider=newapn.Provider(options);
90
94
```
91
95
92
96
The provider will first send an HTTP CONNECT request to the specified proxy in order to establish an HTTP tunnel. Once established, it will create a new secure connection to the Apple Push Notification provider API through the tunnel.
@@ -111,7 +115,7 @@ var options = {
111
115
production:false
112
116
};
113
117
114
-
var apnProvider =newapn.MultiProvider(options);
118
+
constapnProvider=newapn.MultiProvider(options);
115
119
```
116
120
117
121
## Sending a notification
@@ -124,7 +128,7 @@ let deviceToken = "a9d0ed10e9cfd022a61cb08753f49c5a0b0dfb383697bf9f9d750a1003da1
124
128
Create a notification object, configuring it with the relevant parameters (See the [notification documentation](doc/notification.markdown) for more details.)
125
129
126
130
```javascript
127
-
var note =newapn.Notification();
131
+
let note =newapn.Notification();
128
132
129
133
note.expiry=Math.floor(Date.now() /1000) +3600; // Expires 1 hour from now.
This will result in the the following notification payload being sent to the device
@@ -151,7 +158,7 @@ This will result in the the following notification payload being sent to the dev
151
158
Create a Live Activity notification object, configuring it with the relevant parameters (See the [notification documentation](doc/notification.markdown) for more details.)
152
159
153
160
```javascript
154
-
var note =newapn.Notification();
161
+
let note =newapn.Notification();
155
162
156
163
note.expiry=Math.floor(Date.now() /1000) +3600; // Expires 1 hour from now.
157
164
note.badge=3;
@@ -170,9 +177,12 @@ note.contentState = {}
170
177
Send the notification to the API with `send`, which returns a promise.
This will result in the the following notification payload being sent to the device
@@ -182,6 +192,6 @@ This will result in the the following notification payload being sent to the dev
182
192
{"messageFrom":"John Appleseed","aps":{"badge":3,"sound":"ping.aiff","alert":"\uD83D\uDCE7\u2709 You have a new message", "relevance-score":75,"timestamp":1683129662,"stale-date":1683216062,"event":"update","content-state":{}}}
183
193
```
184
194
185
-
You should only create one `Provider` per-process for each certificate/key pair you have. You do not need to create a new `Provider` for each notification. If you are only sending notifications to one app then there is no need for more than one `Provider`.
195
+
## Manage Channels
186
196
187
-
If you are constantly creating `Provider` instances in your app, make sure to call `Provider.shutdown()` when you are done with each provider to release its resources and memory.
Copy file name to clipboardExpand all lines: doc/provider.markdown
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -103,7 +103,7 @@ If you wish to send notifications containing emoji or other multi-byte character
103
103
104
104
Indicate to node-apn that it should close all open connections when the queue of pending notifications is fully drained. This will allow your application to terminate.
105
105
106
-
**Note:** If notifications are pushed after the connection has started, an error will be thrown.
106
+
**Note:** If notifications are pushed after the shutdown has started, an error will be thrown.
Copy file name to clipboardExpand all lines: index.d.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -192,7 +192,7 @@ export class Provider extends EventEmitter {
192
192
/**
193
193
* Indicate to node-apn that it should close all open connections when the queue of pending notifications is fully drained. This will allow your application to terminate.
194
194
*/
195
-
shutdown(callback?: ()=>void): void;
195
+
shutdown(callback?: ()=>void): Promise<void>;
196
196
}
197
197
198
198
exportclassMultiProviderextendsEventEmitter{
@@ -238,7 +238,7 @@ export class MultiProvider extends EventEmitter {
238
238
/**
239
239
* Indicate to node-apn that it should close all open connections when the queue of pending notifications is fully drained. This will allow your application to terminate.
0 commit comments