Cancel a request Alamofire

前端 未结 5 1006
青春惊慌失措
青春惊慌失措 2020-12-23 21:14

I am sending a request which is triggered based on timer. But if I press the back button the request still seems to be active and the response in turns crashes the app. Kind

5条回答
  •  轮回少年
    2020-12-23 21:54

    SWIFT 5

    Alamofire.Session.default.session.getTasksWithCompletionHandler({ dataTasks, uploadTasks, downloadTasks in
                dataTasks.forEach { $0.cancel() }
                uploadTasks.forEach { $0.cancel() }
                downloadTasks.forEach { $0.cancel() }
            })
    

提交回复
热议问题