Skip to content

Commit 97f14ca

Browse files
authored
feat: Add support for watchOS push notifications (#360)
1 parent b851449 commit 97f14ca

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,11 @@ Parse Server Push Adapter currently supports these types of Apple ecosystems:
7272
- `ios`: iPhone, iPad, and iPod touch apps
7373
- `osx`: macOS, and macCatalyst apps
7474
- `tvos`: tvOS apps
75+
- `watchos`: watchOS apps
7576

76-
Delivering push notifications to Apple devices can be done either via Apple Push Notification Service (APNS), or via Firebase Cloud Messaging (FMC). Note that each category of Apple devices require their own configuration section:
77+
Push notifications can be delivered to Apple devices either via Apple Push Notification Service (APNS) or Firebase Cloud Messaging (FMC). Note that each category of Apple devices requires their own configuration section:
7778

78-
- APNS requires a private key that can be downloaded from the Apple Developer Center at https://developer.apple.com/account under _Certificates > Identifiers & Profiles._ The adapter options also require the app ID and team ID which can be found there.
79+
- APNS requires a private key that can be downloaded from the Apple Developer Center at https://developer.apple.com/account under _Certificates > Identifiers & Profiles._ The adapter options also require the app ID and team ID, which can be found there.
7980
- FCM requires a private key that can be downloaded from the Firebase Console at https://console.firebase.google.com in your project under _Settings > Cloud Messaging._
8081

8182
Example options:

spec/ParsePushAdapter.spec.js

+16-6
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,13 @@ describe('ParsePushAdapter', () => {
160160
it('can get valid push types', (done) => {
161161
const parsePushAdapter = new ParsePushAdapter();
162162

163-
expect(parsePushAdapter.getValidPushTypes()).toEqual(['ios', 'osx', 'tvos', 'android', 'fcm', 'web', 'expo']);
163+
expect(parsePushAdapter.getValidPushTypes()).toEqual(['ios', 'osx', 'tvos', 'watchos', 'android', 'fcm', 'web', 'expo']);
164164
done();
165165
});
166166

167167
it('can classify installation', (done) => {
168168
// Mock installations
169-
const validPushTypes = ['ios', 'osx', 'tvos', 'android', 'fcm', 'web', 'expo'];
169+
const validPushTypes = ['ios', 'osx', 'tvos', 'watchos', 'android', 'fcm', 'web', 'expo'];
170170
const installations = [
171171
{
172172
deviceType: 'android',
@@ -180,6 +180,10 @@ describe('ParsePushAdapter', () => {
180180
deviceType: 'tvos',
181181
deviceToken: 'tvosToken'
182182
},
183+
{
184+
deviceType: 'watchos',
185+
deviceToken: 'watchosToken'
186+
},
183187
{
184188
deviceType: 'osx',
185189
deviceToken: 'osxToken'
@@ -208,6 +212,7 @@ describe('ParsePushAdapter', () => {
208212
expect(deviceMap['ios']).toEqual([makeDevice('iosToken', 'ios')]);
209213
expect(deviceMap['osx']).toEqual([makeDevice('osxToken', 'osx')]);
210214
expect(deviceMap['tvos']).toEqual([makeDevice('tvosToken', 'tvos')]);
215+
expect(deviceMap['watchos']).toEqual([makeDevice('watchosToken', 'watchos')]);
211216
expect(deviceMap['web']).toEqual([makeDevice('webToken', 'web')]);
212217
expect(deviceMap['win']).toBe(undefined);
213218
expect(deviceMap['expo']).toEqual([makeDevice('expoToken', 'ios')]);
@@ -395,7 +400,7 @@ describe('ParsePushAdapter', () => {
395400
done();
396401
});
397402

398-
it('reports properly results', (done) => {
403+
it('reports proper results', (done) => {
399404
spyOn(log, 'error').and.callFake(() => {});
400405
const pushConfig = {
401406
web: {
@@ -454,6 +459,11 @@ describe('ParsePushAdapter', () => {
454459
deviceToken: '3e72a1baa92a2febd9a254cbd6584f750c70b2350af5fc9052d1d12584b738e6',
455460
appIdentifier: 'iosbundleId' // ios and tvos share the same bundleid
456461
},
462+
{
463+
deviceType: 'watchos',
464+
deviceToken: '8f72a1baa92a2febd9a254cbd6584f750c70b2350af5fc9052d1d12584b738e6',
465+
appIdentifier: 'iosbundleId' // ios and watchos share the same bundleid
466+
},
457467
{
458468
deviceType: 'web',
459469
deviceToken: JSON.stringify({ endpoint: 'https://fcm.googleapis.com/fcm/send/123' }),
@@ -477,8 +487,8 @@ describe('ParsePushAdapter', () => {
477487
parsePushAdapter.send({ data: { alert: 'some' } }, installations).then((results) => {
478488
expect(Array.isArray(results)).toBe(true);
479489

480-
// 2x iOS, 1x android, 1x osx, 1x tvos, 1x web, 1x expo
481-
expect(results.length).toBe(7);
490+
// 2x iOS, 1x android, 1x osx, 1x tvos, 1x watchos, 1x web, 1x expo
491+
expect(results.length).toBe(8);
482492
results.forEach((result) => {
483493
expect(typeof result.device).toBe('object');
484494
if (!result.device) {
@@ -530,7 +540,7 @@ describe('ParsePushAdapter', () => {
530540
parsePushAdapter.send({data: {alert: 'some'}}, installations).then((results) => {
531541
expect(Array.isArray(results)).toBe(true);
532542

533-
// 2x iOS, 1x android, 1x osx, 1x tvos
543+
// 2x iOS, 1x android, 1x osx, 1x tvos, 1x watchos
534544
expect(results.length).toBe(1);
535545
const result = results[0];
536546
expect(typeof result.device).toBe('object');

src/ParsePushAdapter.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default class ParsePushAdapter {
1515
supportsPushTracking = true;
1616

1717
constructor(pushConfig = {}) {
18-
this.validPushTypes = ['ios', 'osx', 'tvos', 'android', 'fcm', 'web', 'expo'];
18+
this.validPushTypes = ['ios', 'osx', 'tvos', 'watchos', 'android', 'fcm', 'web', 'expo'];
1919
this.senderMap = {};
2020
// used in PushController for Dashboard Features
2121
this.feature = {
@@ -32,6 +32,7 @@ export default class ParsePushAdapter {
3232
switch (pushType) {
3333
case 'ios':
3434
case 'tvos':
35+
case 'watchos':
3536
case 'osx':
3637
if (pushConfig[pushType].hasOwnProperty('firebaseServiceAccount')) {
3738
this.senderMap[pushType] = new FCM(pushConfig[pushType], 'apple');

0 commit comments

Comments
 (0)