1 Reply
      Latest reply on Feb 25, 2020 2:03 AM by eskimo
      NineNine Level 1 Level 1 (0 points)

        Hi

         

        I am writting an App to allow people to divide their day into bite size segments. Each segment is tracked by a timer, and after each segment completed the user is informed of the next segement by a ping(sound).

         

        The core of the application is the

         

                  Timer.publish(every: 1, on: .main, in: .common)

         

        I have set the necessary Background modes - Background Fetch, Remote Notifications, Background Processing, Audio

         

        The app works fine in the simulator. In the background the timer fires away and the sound is played after the completion of each segment. However the same app does not work on the device.

         

        I have noticed a number of threads where contributors have stated that the Timer should not work in the background in the first place. Just dont understand why it works in the Simulator and not the device.

         

        Please help.

        • Re: Timer working in background when run on Simulator, but not on device
          eskimo Apple Staff Apple Staff (13,895 points)

          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"