简体   繁体   中英

How to receive data from NSURLConnectionDelegate when switching from the network?

I am creating a class which communicates with remote server. Currently my device (iPhone 4) is having connectivity via wifi and local network cellular. By default it uses wifi. It works fine in both the cases.

However when I switch from wifi to cell service, it hits error delegate. I want keep communication on going even when connectivity is changed.

Is it possible? How? Thanks,

I don't expect it is possible. Having switched networks, you've probably also switched IP addresses. Connections are defined by the IP addresses of the end points (as well as protocol and protocol-specific data such as port numbers). So, you can't maintain a connection when the IP address changes. You must cleanup and dispose of the broken connection and open a new one.

If the high-level protocol you're using, such as FTP or HTTP, allows it, you can try resuming the data transfer at the point it was interrupted. For example, if downloading a file, you may be able to resume the download at the file position of the last data you received.

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