ios – Apple Push Notifications from a serverless MongoDB App Providers backend
[ad_1]
I’ve been organising Apple Push Notifications for an iOS app, utilizing JSON Internet Tokens relatively than certificates.
I can generate a JWT and make the required POST request from inside the app (utilizing the Swift-JWT package deal) and the notification is delivered.
I’m utilizing MongoDB Realm, which has serverless capabilities (in JavaScript with a Node atmosphere) which might be known as from the iOS app. A scheduled set off updates my JWT, as Apple advise it ought to be refreshed each hour.
Nonetheless, regardless of making an attempt a number of Node modules for making the POST request there have been all the time errors (like “BadDeviceToken” or “InvalidProviderToken”).
I lastly received it working utilizing the node-apn package deal! Nonetheless, I’ve two queries about utilizing it on this serverless perform context:
- It tries to maintain a connection open to the Apple server, which might be advantageous, besides it’d imply a brand new connection is opened each time the perform is known as. Calling
Supplier.shutdown()
doesn’t appear to cease the connection. I don’t assume I can have a long-running course of to obtain future requests in a serverless context. - Apple advise not refreshing the JWT extra usually than each 20 minutes.
node-apn
manages the JWT for you, however in a serverless context, will it’s producing a brand new token each time the perform is known as? Notifications do appear to get delivered each time I take a look at it in growth mode (to the Apple sandbox endpoint).
I’d be glad about readability on these factors, and whether or not node-apn
is acceptable to make use of in serverless capabilities.
[ad_2]