2 Replies
      Latest reply on Oct 23, 2019 12:11 AM by asdassa
      go7202 Level 1 Level 1 (0 points)
        I’m trying to implement background refresh functionality, it will be calling at regular interval of 30min.
        I’ve created a BG task schedular request and mentioned earlier begin date also.
        It’s working while debugging but not working on device keeping in background. 
        Registering the task on AppDelegate didFinishWith options
        
                BGTaskScheduler.shared.register(
                    forTaskWithIdentifier: “IDENTIFIER”,
                    using: DispatchQueue.global()
                ) { task in
        refreshFunctionality()
                }
        
        
        Submitting refresh task request while app going to background
                let request = BGAppRefreshTaskRequest(identifier: "IDENTIFIER")
                request.earliestBeginDate = Date(timeIntervalSinceNow: 30 * 60) 
                
                do {
                    try BGTaskScheduler.shared.submit(request)
                } catch {
                    print("Could not schedule app refresh: \(error)")
                }
        

        Thank you..!

        • Re: BGTaskScheduler not working on Device keeping in background mode.
          eskimo Apple Staff Apple Staff (12,305 points)

          I’m trying to implement background refresh functionality, it will be calling at regular interval of 30min.

          The background app refresh aspects of the new BackgroundTasks framework (specifically, the BGAppRefreshTaskRequest API you’re using) works much like the old background fetch mechanism, and has much the same limitations.  You can use it to request periodic execution time but the system doesn’t guarantee to honour that.  Rather, the system uses its own internal (and very complex) logic to determine which apps should get background refresh time and when, based on various factors like user activity, current battery state, and expected battery usage throughout the rest of the day.

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"

            • Re: BGTaskScheduler not working on Device keeping in background mode.
              asdassa Level 1 Level 1 (0 points)

              I also tried to achieve the same thing but it's not working. I have followed all steps said in WWDC. I am using iPhone XS Max and very less apps are there.

              I created a sample project and used a logger class to save date and time every 15 mins when app goes to background state. Its working only while debugging else not working. I tried to run the WWDC 2019 session 707 example project ColorFeed and its also not updating the data while in background.

              Can you please check on this issue and provide a solution?