How do you detect 3G vs. Wifi connection on mobile safari?

前端 未结 3 865
无人共我
无人共我 2021-02-12 18:04

I am specifically asking about javascript on a mobile webpage, not an objective-c application. Is there something like Apple Reachability for javascript so I can tell when Edge,

3条回答
  •  情深已故
    2021-02-12 18:23

    Although you cannot use data from a browser to detect if the user is on Wifi or a cellular connection - capturing the user's IP may be one way to differentiate between a Wifi and Cellular connection.

    In this article about how cellular impacts your IP address (http://classroom.synonym.com/wifi-change-ip-17586.html) it states the following:

    While on Wi-Fi, your device's public IP will match all other computers on your network, and your router assigns a local IP. While using a cellular connection, your cell carrier assigns a public IP. Connecting to the cellular Internet does not use a router, so your device won't have a local IP.

    IF ip = localIp, then connection = wifiConnection

    IF ip = publicIp, then connection = cellularConnection

    Here's a screenshot of my IP when I'm on cellular:

    enter image description here

    Here's a screenshot of my IP (right after turning off cellular) on Wifi:

    enter image description here

    This could be one answer to the problem without browser help.

提交回复
热议问题