tus / TUSKit

The tus client for iOS.
https://tus.io/
MIT License
214 stars 115 forks source link

Background upload not completing on iOS 17 until app is moved to the foreground #179

Closed r-token closed 11 months ago

r-token commented 11 months ago

Hi there! We've been using TUSKit for a while now and it has been great from the jump. However, we're running into some background upload issues on iOS 17 release builds exclusively.

With the app running in the background, we can still successfully initiate an upload, but it does not complete until the app is moved to the foreground.

I can see that the client's uploadFileAt function is called and the task is scheduled successfully, but for some reason the task is not completing while the app is in the background. There are no warnings or error messages logged.

This works flawlessly from the background on iOS 16. But on 17 we see this behavior consistently - though only from TestFlight release builds. Local dev builds from Xcode also work flawlessly, even on iOS 17. But TestFlight releases on iOS 17 will not upload from the background.

We are using the latest code via Swift Package Manager - pointing to commit hash 2392ed. Using the previous official release (v3.2.0) has the same iOS 17 issue.

Here's our TUSClient initialization if that's helpful:

tusClient = try TUSClient(
    server: URL(string: defaultUrls.tusUrl)!,
    sessionIdentifier: "our identifier",
    sessionConfiguration: .background(withIdentifier: "com.our.identifier.here"),
    storageDirectory: URL(string: "/TUS")!,
    chunkSize: 0 // this enables true background uploads
 )

From what I can tell, this happens on all iOS 17 versions. Though I am specifically running iOS 17.2. Happy to share any other details that might be helpful. Thank you.

donnywals commented 11 months ago

Hi @r-token! thanks for reporting this with such a detailed description. I will take a look as soon as possible (likely after christmas as I'm sure you can imagine).

r-token commented 11 months ago

Sounds great @donnywals! Will keep an eye out. Thank you!

r-token commented 11 months ago

Hey @donnywals, good news! Turns out this was actually due to one of our audio services failing to initialize in the background in some cases (only on iOS 17), which was preventing the audio upload from completing.

So we're good here. I'll close the issue, sorry for wasting your time. Happy holidays!

donnywals commented 11 months ago

Glad you've resolved this! Cheers and happy holidays!