Trigger push notification based on API call response

Hi,

I'm building an app that allows users to get real time data about trains in Portugal and the Metro system in Lisbon. I'm using SwiftUI for frontend.

I would like to add a feature to the app, where the User can add a specific Train to their Favourites list and subscribe to notifications about the status of that Train so that they are aware of any disturbances.

For example, 10 minutes before the train departure time, there would be an API call to fetch the train information, and a notification would be sent to the end-user with the status of the Train.

Can someone tell me if this is possible to do? And if so, how to do it?

Basically, I want to trigger an API call more-or-less at a specific time and, based on the data from the API, send a push notification to the User.

Thanks in advance

Answered by Engineer in 810566022

You can't do this on iOS - you can't trigger your app to run at a specific time or periodically. Your alternatives are to write a server, and you server co-ordinate things and send a push to the app. Alternatively, live activities might be a good fit for what you want to do.

@mungbeans is correct, You cannot trigger an app at a certain time or a certain repeating schedule.

As you already seem to have a server infrastructure for sending push notifications, this would be best controlled from your server side. Once the user adds a train to their favorites, the app can immediately let the server know, and then on the server you could monitor the train statuses and the time, and then send the push notifications as necessary.


Argun Tekant /  DTS Engineer / Core Technologies

Alternatively, live activities might be a good fit for what you want to do.

I'll check the documentation of Live Activities and see if I can use it somehow in the scope of this feature, thanks.

As you already seem to have a server infrastructure for sending push notifications, this would be best controlled from your server side.

I don't have one actually. I'm new to iOS development, never dealt with Notifications or Push Notifications before. Are there any resources you can refer me to for learning on how to implement Push Notifications?

Thank you both

Accepted Answer

Thanks, will take a look at them

Trigger push notification based on API call response
 
 
Q