Alamofire does not work when airplane mode is on

I am developing an iOS download app that uses Alamofire 4.4 and Swift 3.0.

The app gets the url and downloads the file using Alamofire. I am using a background session manager so that the app can load in the background and send a notification when finished.

For some reason, after adding this answer .failure never fires even when airplane mode is enabled. If it turns off airplane mode, the download will continue, but leave it on long enough that it won't continue to download, so you can assume it would cause a crash ...

I have this code for a download request:

    if let resumeData = resumeData {
        request = BackendAPIManager.sharedInstance.alamoFireManager.download(resumingWith: resumeData, to: destination)
    }
    else {
        request = BackendAPIManager.sharedInstance.alamoFireManager.download(extUrl, to: destination)
    }

    alamoRequest = request
        .responseData { response in

            switch response.result {
            case .success:

                //get file path of downloaded file
                let filePath = response.destinationURL?.path

                completeDownload(filePath: filePath!)

            case .failure:

                //this is what never calls on network drop out
                print("Failed")

            }

        .downloadProgress { progress in

            let progressPercent = Float(progress.fractionCompleted)

            //handle other progress stuff

        }
    }

      

.success case triggers are fine and progress returns fine. If I canceled the download using alamoRequest? .Cancel () then it raises the .failure event.

Here's my completion handler:

class BackendAPIManager: NSObject {
    static let sharedInstance = BackendAPIManager()

    var alamoFireManager : Alamofire.SessionManager!

    var backgroundCompletionHandler: (() -> Void)? {
        get {
            return alamoFireManager?.backgroundCompletionHandler
        }
        set {
            alamoFireManager?.backgroundCompletionHandler = newValue
        }
    }

    fileprivate override init()
    {
        let configuration = URLSessionConfiguration.background(withIdentifier: "com.uniqudeidexample.background")
        self.alamoFireManager = Alamofire.SessionManager(configuration: configuration)
    }
}

      

And in my AppDelegate:

func application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void) {

    BackendAPIManager.sharedInstance.backgroundCompletionHandler = completionHandler

    //do other notification stuff...
}

      

Before I added the background session it worked fine and when I activated airplane mode it failed. So am I missing something?

Hope it all makes sense, this is my first app so didn't rely on all the technical possibilities,

thank

+3
ios xcode swift3 download alamofire


source to share


No one has answered this question yet

Check out similar questions:

1665
How can I get the UITextField to move upward when there is a keyboard - when starting editing?
746
Failed to start Xcode process: security
479
"Xcode / iOS license consent requires administrator privileges, please run it as root via sudo." when using GCC
6
fast 2.1 alamofire timeout
4
Resume download after killing or placing in the background of the app
1
Alamofire 3.5.1: download stopped in airplane mode
1
Alamofire: Upload request keeps error as source file even if validation fails
1
Downloaded video from Alamofire does not play in landscape mode
0
Timeout when using NSUrlSession with a call running in the foreground but the application is moved to the background
0
Alamofire chained background tasks



All Articles
Loading...
X
Show
Funny
Dev
Pics