NSURLErrorDomain Code=-997 "Lost connection to background transfer service"
Asked Answered
M

4

17

I am using NSURLSession to download some mp3 files and store them in the device. Everything works fine but sometimes out of the blue, the app crashes and i get this weird error saying NSURLErrorDomain Code=-997 "Lost connection to background transfer service". It does not happen alot but when it does it just messes up the whole app, like when i launch the app the next time all the download tasks are messed up and i just have to rebuild the application on the device to get it to work again. Note that i only get this error since using Xcode 6 and ios8, even though I'm not sure its is related to ios8 or not.

This is the complete error description:

Error Domain=NSURLErrorDomain Code=-997 "Lost connection to background transfer service" UserInfo=0x178664100 {NSErrorFailingURLKey=http://XXXXXXXXXX.mp3, NSLocalizedDescription=Lost connection to background transfer service, NSErrorFailingURLStringKey=http://XXXXXXXXXXX.mp3}
Mendiola answered 8/10, 2014 at 19:49 Comment(6)
have you found a solution? i have the same problemQuaggy
@Quaggy mine had to do something with the URL that the files are being saved to. Ever since i solved that problem i am not getting this error anymore!Mendiola
@jim Did you change the URL the files were being saved to in the delegate method implementation URLSession: downloadTask: didFinishDownloadingToURL: ? I'm encountering the same error, and I'm trying to determine where I need to make the changeRenaterenato
Are you doing this on the main thread?Gerontology
@jim I recommend you to read the following tutorial will give you more perspective on whats going on with your issue.. code.tutsplus.com/tutorials/…Gerontology
@jim were you able to find a solution to this?Amethist
B
1

What version of the SDK are you on? There was a bug in the background transfer daemon that could cause it to crash, which has since been fixed. I would download the latest Xcode beta and try it again.

Bind answered 3/2, 2015 at 19:19 Comment(2)
Well ever since i downloaded xcode 6 and started using ios8 i have not had a problem with background download! you are probably right.Mendiola
I don't think this is necessarily the same bug. I'm using the SDK 8.1 and running on iOS 8.1.3 and also getting occasionally the lost connection error. The funny thing is I get this right after the data has been downloaded successfully! I.e. first the callback URLSession:downloadTask:didFinishDownloadingToURL: with response data and everything OK and immediately after that the callback URLSession:task:didCompleteWithError: is invoked with the 'lost connection' error. I'll be reporting it in a radar.Cindicindie
L
8

My error was that I used a dataTaskWithRequest instead of uploadtaskWithRequest or in your case downloadtaskWithRequest. Obviously a datatask can't run in the background and get's killed.

Laterite answered 13/2, 2015 at 16:1 Comment(4)
What if you want to do a background upload that doesn't have a file associated with it? ie. just some JSON? You have to save it to a file first?Colossian
Yes I solved it by saving the request body into a file.Colossian
@shim, I am getting error when I upload a file which has contents of request body. can you share me some codes for it?Balanchine
Sorry, I don't have access to that code anymore. Anyway, I would imagine any such error really depends on the server you're using.Colossian
B
1

What version of the SDK are you on? There was a bug in the background transfer daemon that could cause it to crash, which has since been fixed. I would download the latest Xcode beta and try it again.

Bind answered 3/2, 2015 at 19:19 Comment(2)
Well ever since i downloaded xcode 6 and started using ios8 i have not had a problem with background download! you are probably right.Mendiola
I don't think this is necessarily the same bug. I'm using the SDK 8.1 and running on iOS 8.1.3 and also getting occasionally the lost connection error. The funny thing is I get this right after the data has been downloaded successfully! I.e. first the callback URLSession:downloadTask:didFinishDownloadingToURL: with response data and everything OK and immediately after that the callback URLSession:task:didCompleteWithError: is invoked with the 'lost connection' error. I'll be reporting it in a radar.Cindicindie
S
1

Probably Background Transfer daemon crashed. Try to check crash logs on your device. May be you will find something interesting there.

Servais answered 10/2, 2015 at 16:43 Comment(0)
E
0

I had this issue with AVAssetDownloadTask, and it turned out to be because I was creating tasks without starting them.

Epicedium answered 12/7, 2018 at 17:11 Comment(1)
can you please elaborate, i am facing the same issueMetallize

© 2022 - 2024 — McMap. All rights reserved.