Skip to content

Commit 9511ac7

Browse files
committed
RE1-T88 Trying to use FCM for APNS
1 parent 30ee271 commit 9511ac7

File tree

1 file changed

+14
-63
lines changed

1 file changed

+14
-63
lines changed

src/services/push-notification.ts

Lines changed: 14 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,19 @@ class PushNotificationService {
8282
await this.setupAndroidNotificationChannels();
8383

8484
// Configure notifications behavior
85-
Notifications.setNotificationHandler({
86-
handleNotification: async () => ({
87-
shouldShowAlert: true,
88-
shouldPlaySound: true,
89-
shouldSetBadge: false,
90-
shouldShowBanner: true,
91-
shouldShowList: true,
92-
}),
93-
});
85+
//Notifications.setNotificationHandler({
86+
// handleNotification: async () => ({
87+
// shouldShowAlert: true,
88+
// shouldPlaySound: true,
89+
// shouldSetBadge: false,
90+
// shouldShowBanner: true,
91+
// shouldShowList: true,
92+
// }),
93+
//});
9494

9595
// Set up notification listeners and store the subscription handles
96-
this.notificationReceivedListener = Notifications.addNotificationReceivedListener(this.handleNotificationReceived);
97-
this.notificationResponseListener = Notifications.addNotificationResponseReceivedListener(this.handleNotificationResponse);
96+
//this.notificationReceivedListener = Notifications.addNotificationReceivedListener(this.handleNotificationReceived);
97+
//this.notificationResponseListener = Notifications.addNotificationResponseReceivedListener(this.handleNotificationResponse);
9898

9999
// Listen for foreground messages and store the unsubscribe function
100100
this.fcmOnMessageUnsubscribe = messaging().onMessage(async (remoteMessage) => {
@@ -198,11 +198,12 @@ class PushNotificationService {
198198
}
199199

200200
// Get the token using the non-Expo push notification service method
201-
const devicePushToken = await Notifications.getDevicePushTokenAsync();
201+
//const devicePushToken = await Notifications.getDevicePushTokenAsync();
202202

203203
// The token format depends on the platform
204-
const token = Platform.OS === 'ios' ? devicePushToken.data : devicePushToken.data;
204+
//const token = Platform.OS === 'ios' ? devicePushToken.data : devicePushToken.data;
205205

206+
const token = await messaging().getToken();
206207
this.pushToken = token as string;
207208

208209
logger.info({
@@ -232,60 +233,10 @@ class PushNotificationService {
232233
}
233234
}
234235

235-
// Method to send the token to your backend
236-
private async sendTokenToBackend(token: string, unitId: string): Promise<void> {
237-
// Implement your API call to register the token with your backend
238-
// This is where you would associate the token with the unitId
239-
try {
240-
// Example implementation:
241-
// await api.post('/register-push-token', { token, unitId });
242-
243-
logger.info({
244-
message: 'Push token registered with backend',
245-
context: { token, unitId },
246-
});
247-
} catch (error) {
248-
logger.error({
249-
message: 'Failed to register push token with backend',
250-
context: { error, token, unitId },
251-
});
252-
}
253-
}
254-
255236
public getPushToken(): string | null {
256237
return this.pushToken;
257238
}
258239

259-
public async sendTestNotification(): Promise<void> {
260-
if (!this.pushToken) {
261-
logger.warn({
262-
message: 'Cannot send test notification - no push token available',
263-
});
264-
return;
265-
}
266-
267-
try {
268-
// This is a local test notification, not sent through a server
269-
await Notifications.scheduleNotificationAsync({
270-
content: {
271-
title: 'Test Notification',
272-
body: 'This is a test notification from Resgrid Unit',
273-
data: { type: 'test', timestamp: new Date().toISOString() },
274-
},
275-
trigger: null, // Send immediately
276-
});
277-
278-
logger.info({
279-
message: 'Test notification sent',
280-
});
281-
} catch (error) {
282-
logger.error({
283-
message: 'Failed to send test notification',
284-
context: { error },
285-
});
286-
}
287-
}
288-
289240
public cleanup(): void {
290241
if (this.notificationReceivedListener) {
291242
this.notificationReceivedListener.remove();

0 commit comments

Comments
 (0)