Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cancel all requests after migrating from Alamofire v3 to v4?

I used this code to cancel all Alamofire requests:

func stopAllSessions() {
    Alamofire.Manager.sharedInstance.session.getAllTasksWithCompletionHandler { tasks in
        tasks.forEach { $0.cancel() }
    }
}

After swift 3 migration, this doesn't work, and I can't find getAllTasksWithCompletionHandler method in SessionManager of Alamofire 4.

like image 329
Ruslan Sabirov Avatar asked Feb 06 '23 21:02

Ruslan Sabirov


1 Answers

Found:

    Alamofire.SessionManager.default.session.getTasksWithCompletionHandler { (sessionDataTask, uploadData, downloadData) in
        sessionDataTask.forEach { $0.cancel() }
        uploadData.forEach { $0.cancel() }
        downloadData.forEach { $0.cancel() }
    }
like image 112
Ruslan Sabirov Avatar answered May 15 '23 06:05

Ruslan Sabirov