Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Background Download Task is not working #5501

Closed
shamith-kumar-sclera opened this issue Jan 31, 2025 · 4 comments
Closed

Background Download Task is not working #5501

shamith-kumar-sclera opened this issue Jan 31, 2025 · 4 comments

Comments

@shamith-kumar-sclera
Copy link

The Download is not Working in the background mode even if i entitled all the necessary permission for the application it only works when the app is connected to xcode due to xcode keep the session alive but if try after removing the connection from the xcode the app not able to keep the download after 45 sec what may be the reason

my code

  var request = URLRequest(url: url)
        request.httpMethod = "GET"
        
        let bearerToken = SyncManager.accessToken
        request.setValue("Bearer \(bearerToken)", forHTTPHeaderField: "Authorization")
        
        let uniqueIdentifier = "\(self.vdmsId)_\(UUID().uuidString)"
        
        backgroundTaskID = UIApplication.shared.beginBackgroundTask { [weak self] in
            if let taskID = self?.backgroundTaskID {
                UIApplication.shared.endBackgroundTask(taskID)
                self?.backgroundTaskID = .invalid
            }
        }
        
        
        let CursessionConfig = URLSessionConfiguration.background(withIdentifier: uniqueIdentifier)
        
        
        CursessionConfig.isDiscretionary = false
        CursessionConfig.sessionSendsLaunchEvents = true
        CursessionConfig.shouldUseExtendedBackgroundIdleMode = true
           
           // Set timeout intervals
        CursessionConfig.timeoutIntervalForResource = 24 * 60 * 60 // 24 hours
        CursessionConfig.timeoutIntervalForRequest = 60 * 60 // 1 hour
        
        let Cursession = URLSession(configuration: CursessionConfig, delegate: self, delegateQueue: nil)
        
        
        self.CurInstanceSession  = Cursession
        
        
        self.session = Cursession
        if  SyncManager.activeSessions == nil {
            SyncManager.activeSessions = [URLSession]()
        }
        
        SyncManager.activeSessions?.append(Cursession)
        
        self.downloadCompletionHandler = completion
        
        let CurdownloadTask = Cursession.downloadTask(with: request)
        
        CurdownloadTask.resume()

is there any solutions and i have entitled all the neccessary permisssions like background fetch, process and i also tries with the UIApplication.shared.beginBackgroundTask but after 45 sec it gets terminated all of the suden what may be the issue

@github-actions github-actions bot added pending-triage Issue is pending triage pending-maintainer-response Issue is pending response from an Amplify team member labels Jan 31, 2025
@harsh62
Copy link
Member

harsh62 commented Jan 31, 2025

@shamith-kumar-sclera Can you please try using the Transfer Utility as described here in this documentation https://docs.amplify.aws/gen1/swift/sdk/storage/transfer-utility/

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify team member label Jan 31, 2025
@shamith-kumar-sclera
Copy link
Author

@harsh62 thank you for the replay, but i am not using the the AWS s3 bucket mine is simple file download from the REST server running remotely
since this is similar to the issue you faced once can you provide me the insights on this issue (not working in the background after 45 sec in the background)

@github-actions github-actions bot added the pending-maintainer-response Issue is pending response from an Amplify team member label Feb 3, 2025
@harsh62
Copy link
Member

harsh62 commented Feb 3, 2025

@shamith-kumar-sclera Unfortunately I can only help you with AWS SDK related questions.

@harsh62 harsh62 closed this as completed Feb 3, 2025
@github-actions github-actions bot removed pending-triage Issue is pending triage pending-maintainer-response Issue is pending response from an Amplify team member labels Feb 3, 2025
Copy link

github-actions bot commented Feb 3, 2025

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants