3 Replies
      Latest reply on Aug 28, 2019 12:34 AM by eskimo
      mksmurali Level 1 Level 1 (0 points)

        Hi,

           I used URLSession to call Api.

         

        Code sample :

                 let defaultSessionConfiguration = URLSessionConfiguration.default

                defaultSessionConfiguration.timeoutIntervalForRequest = 600

                defaultSessionConfiguration.timeoutIntervalForResource = 600

                defaultSessionConfiguration.urlCache = URLCache(memoryCapacity: 0, diskCapacity: 0, diskPath: nil)

                defaultSessionConfiguration.requestCachePolicy = .reloadIgnoringLocalAndRemoteCacheData

         

                let defaultSession = URLSession(configuration: defaultSessionConfiguration)

         

                 let task = defaultSession.dataTask(with: urlRequest) { data, response, error in

                  ...

                 }

                  task.resume()

            }

         

        When service was called and it was not completed,I pressed home button.

        So app went to background state.

        And Api call was failed....

         

        How to make Api call to get success in this scenerio and what is reason for api call failure?

        Thanks in advance for the supporter.

        • Re: Service Not working when app goes background
          Claude31 Level 8 Level 8 (6,975 points)

          WHere do you put this code ?

           

          can you show your complete code for

              func applicationWillEnterForeground(_ application: UIApplication) { }

           

          and for

           

              func applicationDidBecomeActive(_ application: UIApplication) { }

           

          and

           

              func applicationWillEnterForeground(_ application: UIApplication) {

            • Re: Service Not working when app goes background
              mksmurali Level 1 Level 1 (0 points)

              Hi

              I put this code in a separate swift file.

              I didnt implement anything in applicationWillEnterForeground and in applicationDidBecomeActive.

               

              when app moves to background and after few seconds when it comes to foreground,my webApi call is failed.

              By surfing the internet i understood that ,after app moves to background,and with in few more seconds it will beforcibly moved to suspened state.

              So my webApi call failed.

              How to make my webApi call to get success even when app goes to background state?

            • Re: Service Not working when app goes background
              eskimo Apple Staff Apple Staff (12,305 points)

              How to make my webApi call to get success even when app goes to background state?

              Please read this post and then write back if you have further questions.

              Share and Enjoy

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