简体   繁体   中英

How to handle a change in network mid request - Alamofire

I am facing an issue in my application whereby a HTTP request is made with Alamofire, and whilst it is running, the user opens the control centre and disables WiFi, effectively switching the network the call is running over from WiFi to mobile data such as 4G. This causes the network call to fail with 'The network connection was lost'.

This logs the user out of the app as it is a critical call that needs to succeed to use the app, I feel like Alamofire must have some built in way of handling this?

If you opt in to Multipath TCP using handover this will be handled automatically. You do it by setting the multipathServiceType on the configuration of the underlying URLSession, It requires the server to support it though.

https://developer.apple.com/documentation/foundation/nsurlsessionconfiguration/improving_network_reliability_using_multipath_tcp?language=objc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM