Ive been developing an app that gives prayer times notifications 5 times a day. The times everyday are different, so I need to get the data from an API for each specific day. How can I implement this feature in swift.
Ive tried and currently have a solution that creates local notifications for the next 12 days for each app launch, but this solution is definitely not efficient and it would be better if there was a more efficient solution.
This sounds exactly correct. I would recommend adding background app refresh, and possibly a fallback to a push notification for cases where the app has not been launched in a long time, but your current design is an excellent start. There's nothing inefficient about it. Scheduling local notifications is extremely cheap for the system.
Since I assume your notifications rely on the local sunrise and sunset, I would also suggest registering for significant location changes. If the user travels, this can (with the user's permission) wake your app to reschedule the notifications. There is very little battery cost to responding to significant location changes. The user flows required to request permission are a little complicated, so I highly recommend watching WWDC19: What's New in Core Location to learn how to do it correctly. As a nice side-effect, this will tend to wake up your app more often (whenever the user moves around 500m or so), giving you more opportunities to schedule your notifications.