Skip to content

Commit

Permalink
ongoing expo-notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud AMBROSELLI committed Jul 11, 2024
1 parent 6fe1d41 commit a090a0c
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions expo/src/services/deepLink.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as Linking from "expo-linking";
import NotificationService from "./notifications";
import * as Notifications from "expo-notifications";

export const deepLinkingConfig = {
prefixes: ["oz://"],
Expand Down Expand Up @@ -63,27 +64,34 @@ export const deepLinkingConfig = {
return url;
}

// Check if there is an initial notification
const notification = NotificationService.popInitialNotification();
// Handle URL from expo push notifications
const response = await Notifications.getLastNotificationResponseAsync();

// Get deep link from data
// if this is undefined, the app will open the default/home page
return notification?.data?.link;
return response?.notification.request.content.data.url;
},
subscribe(listener) {
// Listen to incoming links from deep linking
const linkingSubscription = Linking.addEventListener("url", ({ url }) => {
listener(url);
});

const unsubscribeNotificationService = NotificationService.subscribe((notification) => {
if (notification?.data?.link) listener(notification.data.link);
});
// Listen to expo push notifications
const notificationsSubscription = Notifications.addNotificationResponseReceivedListener(
(response) => {
const url = response.notification.request.content.data.link;

// Any custom logic to see whether the URL needs to be handled
//...

// Let React Navigation handle the URL
if (url) listener(url);
}
);

return () => {
// Clean up the event listeners
linkingSubscription.remove();
unsubscribeNotificationService();
notificationsSubscription.remove();
};
},
};

0 comments on commit a090a0c

Please sign in to comment.