1

I have written a code to execute in background as follows

DispatchQueue.global(qos: .background).async {
            for index in 1...50 {
                print("\(index)")
                usleep(1000000)
            }
            DispatchQueue.main.async {
                print("done")
            }
        }

but when i press home and app goes to background code execution stops

How to to keep it running even when app goes in background

LynAs
  • 6,407
  • 14
  • 48
  • 83
  • 1
    Short answer; you can't. There are specific background modes available on iOS for certain tasks. These are covered in the iOS application programming guide from Apple – Paulw11 Jan 04 '17 at 09:30
  • i want to upload list of files serially in background even when app. How can i do this?? can answer for if or point me to some link?? – LynAs Jan 04 '17 at 09:33
  • Read more https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html – Qamar Jan 04 '17 at 09:33
  • 1
    Also check this is specific to your need http://stackoverflow.com/a/23831862/5710872 – Qamar Jan 04 '17 at 09:34

0 Answers0