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

Add Amplify Storage API for resuming app when background transfer completes #1102

Closed
palpatim opened this issue Mar 12, 2021 · 2 comments
Closed
Labels
feature-request Request a new feature storage Issues related to the Storage category

Comments

@palpatim
Copy link
Member

In aws-amplify/docs#2699 (comment), @ptwobrussell noted that we do not provide documentation or an API for resuming an app when a background transfer completes.

We should investigate the various ways our supported iOS versions notify an app that the session has completed, and ensure we provide clear documentation and necessary Amplify Storage APIs for re-launching an app when a transfer completes.


Just to circle back on this, I have figured out the solution.

1 - In terms of the code itself, you'll just drop in something to this effect into your AppDelegate.swift file. What makes it a bit non-obvious is that you're importing AWSS3 directly and there are no references to Amplify.

import Foundation
import UIKit
import AWSS3
import os.log


// Needed to handle completion of background sessions for file uploads
// If you're working on a new project with SwiftUI and iOS13+ you'll have to go out of your way to wire up `AppDelegate` through
// the @UIApplicationDelegateAdaptor property wrapper
class AppDelegate: NSObject, UIApplicationDelegate {
       
    func application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void) {
        os_log("handleEventsForBackgroundUrlSession: %{public}@", log: OSLog.fileupload, type: .debug, identifier)
        AWSS3TransferUtility.interceptApplication(application, handleEventsForBackgroundURLSession: identifier, completionHandler: completionHandler)
    }
    
}

2 - Here's the part that was really at the root of most of my troubles: in iOS 13+, it's possible that your iOS Settings can be inadvertently configured so that iOS never resumes/relaunches your app, which can be incredibly confusing and send you on lots of wild goose chases if you don't already know about this. See https://developer.apple.com/forums/thread/124265?answerId=388440022#388440022

This was a fairly painful and confusing debugging process to get to to the bottom of this. Given how common a use case it is to upload large files, I hope this is helpful to someone else.

Originally posted by @ptwobrussell in aws-amplify/docs#2699 (comment)

@github-actions
Copy link
Contributor

This issue is stale because it has been open for 14 days with no activity. Please, provide an update or it will be automatically closed in 7 days.

@github-actions github-actions bot added closing soon This issue will be closed in 7 days unless further comments are made. and removed closing soon This issue will be closed in 7 days unless further comments are made. labels Jun 19, 2021
@royjit
Copy link
Contributor

royjit commented Feb 10, 2023

PR that will enable to invoke handleEventsForBackgroundURLSession - #2481

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request a new feature storage Issues related to the Storage category
Projects
None yet
Development

No branches or pull requests

3 participants