2

My Objective is running code at certain time, no matter the app is in background or terminated.

I tried using RunLoop but this option doesn't work when the app is not in foreground state.

Would be there anyway to achieve this? Thanks ;)

edit: certain time refers to time like 12:00 AM, or 3:00 PM

Rob Napier
  • 286,113
  • 34
  • 456
  • 610
Max Wells
  • 79
  • 4
  • 1
    See https://stackoverflow.com/questions/44017458/call-a-web-service-from-ios-at-a-particular-time-daily-in-the-background. This question is unrelated to SwiftUI, and I assume relates specifically to iOS. – Rob Napier Apr 17 '20 at 17:43
  • 1
    Max, this just isn’t how background tasks work. In general, the OS dictates when your app is awakened to perform some background tasks. With background fetch, the timing is influenced by when the user historically fires up your app. With the new background processing task, it looks like it’s done at night when charging, but not at a particular time. But short of user notifications and/or push notifications, the idea of running something exactly at some time in the afternoon, say 3pm, is a bit of a non-starter. And if a user force-quit’s an app, all bets are off, regardless. – Rob Apr 18 '20 at 14:20
  • aren't background services supported in ios? – chitgoks Feb 24 '23 at 07:21

0 Answers0