Skip to content

feat: Add support for watchOS push notifications #360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ Parse Server Push Adapter currently supports these types of Apple ecosystems:
- `ios`: iPhone, iPad, and iPod touch apps
- `osx`: macOS, and macCatalyst apps
- `tvos`: tvOS apps
- `watchos`: watchOS apps

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:
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:

- 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.
- 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.
- 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._

Example options:
Expand Down
22 changes: 16 additions & 6 deletions spec/ParsePushAdapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@ describe('ParsePushAdapter', () => {
it('can get valid push types', (done) => {
const parsePushAdapter = new ParsePushAdapter();

expect(parsePushAdapter.getValidPushTypes()).toEqual(['ios', 'osx', 'tvos', 'android', 'fcm', 'web', 'expo']);
expect(parsePushAdapter.getValidPushTypes()).toEqual(['ios', 'osx', 'tvos', 'watchos', 'android', 'fcm', 'web', 'expo']);
done();
});

it('can classify installation', (done) => {
// Mock installations
const validPushTypes = ['ios', 'osx', 'tvos', 'android', 'fcm', 'web', 'expo'];
const validPushTypes = ['ios', 'osx', 'tvos', 'watchos', 'android', 'fcm', 'web', 'expo'];
const installations = [
{
deviceType: 'android',
Expand All @@ -180,6 +180,10 @@ describe('ParsePushAdapter', () => {
deviceType: 'tvos',
deviceToken: 'tvosToken'
},
{
deviceType: 'watchos',
deviceToken: 'watchosToken'
},
{
deviceType: 'osx',
deviceToken: 'osxToken'
Expand Down Expand Up @@ -208,6 +212,7 @@ describe('ParsePushAdapter', () => {
expect(deviceMap['ios']).toEqual([makeDevice('iosToken', 'ios')]);
expect(deviceMap['osx']).toEqual([makeDevice('osxToken', 'osx')]);
expect(deviceMap['tvos']).toEqual([makeDevice('tvosToken', 'tvos')]);
expect(deviceMap['watchos']).toEqual([makeDevice('watchosToken', 'watchos')]);
expect(deviceMap['web']).toEqual([makeDevice('webToken', 'web')]);
expect(deviceMap['win']).toBe(undefined);
expect(deviceMap['expo']).toEqual([makeDevice('expoToken', 'ios')]);
Expand Down Expand Up @@ -395,7 +400,7 @@ describe('ParsePushAdapter', () => {
done();
});

it('reports properly results', (done) => {
it('reports proper results', (done) => {
spyOn(log, 'error').and.callFake(() => {});
const pushConfig = {
web: {
Expand Down Expand Up @@ -454,6 +459,11 @@ describe('ParsePushAdapter', () => {
deviceToken: '3e72a1baa92a2febd9a254cbd6584f750c70b2350af5fc9052d1d12584b738e6',
appIdentifier: 'iosbundleId' // ios and tvos share the same bundleid
},
{
deviceType: 'watchos',
deviceToken: '8f72a1baa92a2febd9a254cbd6584f750c70b2350af5fc9052d1d12584b738e6',
appIdentifier: 'iosbundleId' // ios and watchos share the same bundleid
},
{
deviceType: 'web',
deviceToken: JSON.stringify({ endpoint: 'https://fcm.googleapis.com/fcm/send/123' }),
Expand All @@ -477,8 +487,8 @@ describe('ParsePushAdapter', () => {
parsePushAdapter.send({ data: { alert: 'some' } }, installations).then((results) => {
expect(Array.isArray(results)).toBe(true);

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

// 2x iOS, 1x android, 1x osx, 1x tvos
// 2x iOS, 1x android, 1x osx, 1x tvos, 1x watchos
expect(results.length).toBe(1);
const result = results[0];
expect(typeof result.device).toBe('object');
Expand Down
3 changes: 2 additions & 1 deletion src/ParsePushAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class ParsePushAdapter {
supportsPushTracking = true;

constructor(pushConfig = {}) {
this.validPushTypes = ['ios', 'osx', 'tvos', 'android', 'fcm', 'web', 'expo'];
this.validPushTypes = ['ios', 'osx', 'tvos', 'watchos', 'android', 'fcm', 'web', 'expo'];
this.senderMap = {};
// used in PushController for Dashboard Features
this.feature = {
Expand All @@ -32,6 +32,7 @@ export default class ParsePushAdapter {
switch (pushType) {
case 'ios':
case 'tvos':
case 'watchos':
case 'osx':
if (pushConfig[pushType].hasOwnProperty('firebaseServiceAccount')) {
this.senderMap[pushType] = new FCM(pushConfig[pushType], 'apple');
Expand Down
Loading