Just dont understand why it works in the Simulator and not the device.
Because the simulator is a simulator, not an emulator. There are many places where the simulator does not accurately simulate device behaviour. Ultimately you have to target a real device.
In this specific case, the simulator’s support for suspending apps as they enter the background has never been super reliable.
Coming back to your real issue, it’s unlikely that you’ll be able to meet your goals as they currently stand. iOS puts strict limits on background execution and there’s no way to run indefinitely in the background without performing some user-meaningful activity (like a background music player). There’s also no way to tell the system to resume your app in the background at some specific point in time.
If I were in your shoes, I’d look at using local notifications for this (via the UserNotifications framework). These have their own set of limitations, of course, but you’re likely to make more sustainable progress with them.
Share and Enjoy
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"