Search code examples
androidreact-nativeapollo-clientreact-apollo

Does Apollo Subscription works in Background and Quit State in react native?


I want Apollo Subscriptions to work even if app is in background or quit state. Is it possible ?


Solution

  • This post is a bit old, but can be usefull to have an answer.

    Apollo Subscription stop working if you close your app.

    I'm not sure if a sub can work in background (probably yes) but I advise against this practice anyway, as a background task can be killed by both OS at any time (for ressource saving), and you haven't the possibility to oppose it.

    If you want to make an equivalent of Push Notification (and I assume that this is the usecase you have in mind for subscription in background), you will need to use the classical solutions for that.

    This is easier to make Push Notification when using Expo that had build in solution (see link) : https://docs.expo.dev/push-notifications/overview/

    If you don't use Expo, this will be a bit more challenging to integrate Notification Push :

    • You will need to use a dedicate library (I advise this one, but there's other : https://github.com/zo0r/react-native-push-notification )
    • You will also need to manually create AuthToken from the FCM (Firebase Cloud Messaging) service to send push notification to Android (same as before, alternate solution exist).
    • You will also need to make the same with APNs (Apple Push Notification service) for sending Push notification to IOS.
    • Lastly, if you have React Navigation and want to open a specific screen from a Push Notification, you will need to use the deeplinking functionnality of React Navigation (as it is mandatory to init your Push Notification at the root of your app, and that your AppNavigation provider will not be init when clicking on your Push Notification).