diff options
author | Mårten Nordheim <marten.nordheim@qt.io> | 2021-10-18 17:48:36 +0200 |
---|---|---|
committer | Mårten Nordheim <marten.nordheim@qt.io> | 2021-10-29 13:01:55 +0200 |
commit | a6947853ee0181098d963dab315c59b926187c42 (patch) | |
tree | 67af328bc575d6ea103b58b6cc6222740991c2b0 /src/plugins/networkinformation | |
parent | f40e0bcf674e03ce78751a799c2f0fb6f2b8b086 (diff) |
QNI: transportMedium support for iOS
It can only differentiate between cellular and not cellular
and then we can determine if it's disconnected or (presumably) using
wifi.
It is also explicitly not supported on macOS, which adds to the
confusion.
Task-number: QTBUG-91023
Change-Id: I1d002ba06dd9acf1a0daabfb2a4193c07871e9b4
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/plugins/networkinformation')
-rw-r--r-- | src/plugins/networkinformation/scnetworkreachability/qscnetworkreachabilitynetworkinformationbackend.mm | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/src/plugins/networkinformation/scnetworkreachability/qscnetworkreachabilitynetworkinformationbackend.mm b/src/plugins/networkinformation/scnetworkreachability/qscnetworkreachabilitynetworkinformationbackend.mm index 1da671e549..272327f7da 100644 --- a/src/plugins/networkinformation/scnetworkreachability/qscnetworkreachabilitynetworkinformationbackend.mm +++ b/src/plugins/networkinformation/scnetworkreachability/qscnetworkreachabilitynetworkinformationbackend.mm @@ -69,12 +69,20 @@ public: static QNetworkInformation::Features featuresSupportedStatic() { - return QNetworkInformation::Features(QNetworkInformation::Feature::Reachability); + return QNetworkInformation::Features(QNetworkInformation::Feature::Reachability +#ifdef QT_PLATFORM_UIKIT + | QNetworkInformation::Feature::TransportMedium +#endif + ); } private Q_SLOTS: void reachabilityChanged(bool isOnline); +#ifdef QT_PLATFORM_UIKIT + void isWwanChanged(bool isOnline); +#endif + private: Q_DISABLE_COPY_MOVE(QSCNetworkReachabilityNetworkInformationBackend); @@ -110,10 +118,16 @@ private: QSCNetworkReachabilityNetworkInformationBackend::QSCNetworkReachabilityNetworkInformationBackend() { bool isOnline = false; +#ifdef QT_PLATFORM_UIKIT + bool isWwan = false; +#endif if (ipv4Probe.setTargets(QHostAddress::AnyIPv4, {})) { // We manage to create SCNetworkReachabilityRef for IPv4, let's // read the last known state then! isOnline |= ipv4Probe.isReachable(); +#ifdef QT_PLATFORM_UIKIT + isWwan |= ipv4Probe.isWwan(); +#endif ipv4Probe.startMonitoring(); } @@ -121,9 +135,15 @@ QSCNetworkReachabilityNetworkInformationBackend::QSCNetworkReachabilityNetworkIn // We manage to create SCNetworkReachability ref for IPv6, let's // read the last known state then! isOnline |= ipv6Probe.isReachable(); +#ifdef QT_PLATFORM_UIKIT + isWwan |= ipv6Probe.isWwan(); +#endif ipv6Probe.startMonitoring(); } reachabilityChanged(isOnline); +#ifdef QT_PLATFORM_UIKIT + isWwanChanged(isWwan); +#endif connect(&ipv4Probe, &QNetworkConnectionMonitor::reachabilityChanged, this, &QSCNetworkReachabilityNetworkInformationBackend::reachabilityChanged, @@ -131,6 +151,15 @@ QSCNetworkReachabilityNetworkInformationBackend::QSCNetworkReachabilityNetworkIn connect(&ipv6Probe, &QNetworkConnectionMonitor::reachabilityChanged, this, &QSCNetworkReachabilityNetworkInformationBackend::reachabilityChanged, Qt::QueuedConnection); + +#ifdef QT_PLATFORM_UIKIT + connect(&ipv4Probe, &QNetworkConnectionMonitor::isWwanChanged, this, + &QSCNetworkReachabilityNetworkInformationBackend::isWwanChanged, + Qt::QueuedConnection); + connect(&ipv6Probe, &QNetworkConnectionMonitor::isWwanChanged, this, + &QSCNetworkReachabilityNetworkInformationBackend::isWwanChanged, + Qt::QueuedConnection); +#endif } QSCNetworkReachabilityNetworkInformationBackend::~QSCNetworkReachabilityNetworkInformationBackend() @@ -143,6 +172,23 @@ void QSCNetworkReachabilityNetworkInformationBackend::reachabilityChanged(bool i : QNetworkInformation::Reachability::Disconnected); } +#ifdef QT_PLATFORM_UIKIT +void QSCNetworkReachabilityNetworkInformationBackend::isWwanChanged(bool isWwan) +{ + // The reachability API from Apple only has one entry regarding transport medium: "IsWWAN"[0]. + // This is _serviceable_ on iOS where the only other credible options are "WLAN" or + // "Disconnected". But on macOS you could be connected by Ethernet as well, so how would that be + // reported? It doesn't matter anyway since "IsWWAN" is not available on macOS. + // [0]: https://developer.apple.com/documentation/systemconfiguration/scnetworkreachabilityflags/kscnetworkreachabilityflagsiswwan?language=objc + if (reachability() == QNetworkInformation::Reachability::Disconnected) { + setTransportMedium(QNetworkInformation::TransportMedium::Unknown); + } else { + setTransportMedium(isWwan ? QNetworkInformation::TransportMedium::Cellular + : QNetworkInformation::TransportMedium::WiFi); + } +} +#endif + QT_END_NAMESPACE #include "qscnetworkreachabilitynetworkinformationbackend.moc" |