How do I force an iOS app to use 3G instead of WiFi?

后端 未结 3 717
逝去的感伤
逝去的感伤 2020-12-16 07:57

I want to use a messaging protocol that works fine over 3G, but not over some corporate firewalls. How can my app force the use of the cellular network when it fails to conn

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-16 08:24

    Use getifaddrs to enumerate the network interfaces. Look for ifa_name that starts with "pdp." This will be the cellular interface (e.g., pdp_ip0). Test (ifa_flags & IFF_UP) to make sure the interface is up, and get the IP address from ifa_addr. Then use bind() to bind your socket to that address.

    Not sure how you activate the cellular interface if it is not already up. Normally, I just make a high level http call to get iOS to wake up the network, but not sure under what conditions the cellular service becomes active when wifi is also available. I suspect it is usually there as a fallback to the wifi.

提交回复
热议问题