Fix frequent reconnects on iOS
Tries to guess the used bearer type on iOS and only reconnect if that one changes.
This commit is contained in:
parent
20287d6ba9
commit
71b1885004
@ -58,7 +58,10 @@ NymeaConnection::NymeaConnection(QObject *parent) : QObject(parent)
|
|||||||
#ifdef Q_OS_IOS
|
#ifdef Q_OS_IOS
|
||||||
connect(m_networkReachabilityMonitor, &NetworkReachabilityMonitor::availableBearerTypesChanged, this, [this](){
|
connect(m_networkReachabilityMonitor, &NetworkReachabilityMonitor::availableBearerTypesChanged, this, [this](){
|
||||||
if (m_currentTransport) {
|
if (m_currentTransport) {
|
||||||
m_currentTransport->disconnect();
|
if (!m_networkReachabilityMonitor->availableBearerTypes().testFlag(m_usedBearerType)) {
|
||||||
|
qCInfo(dcNymeaConnection()) << "Used bearer type" << m_usedBearerType << "isn't available any more. Reconnecting.";
|
||||||
|
m_currentTransport->disconnect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
@ -292,6 +295,17 @@ void NymeaConnection::onConnected()
|
|||||||
if (!m_currentTransport) {
|
if (!m_currentTransport) {
|
||||||
m_currentTransport = newTransport;
|
m_currentTransport = newTransport;
|
||||||
qCInfo(dcNymeaConnection()) << "Connected to" << m_currentHost->name() << "via" << m_currentTransport->url() << m_currentTransport->isEncrypted();
|
qCInfo(dcNymeaConnection()) << "Connected to" << m_currentHost->name() << "via" << m_currentTransport->url() << m_currentTransport->isEncrypted();
|
||||||
|
#ifdef Q_OS_IOS
|
||||||
|
// We can't know for sure which transport we're actually using, but let's assume the OS picked from the available ones in the order LAN, WiFi, MobileData
|
||||||
|
if (m_networkReachabilityMonitor->availableBearerTypes().testFlag(NymeaConnection::BearerTypeEthernet)) {
|
||||||
|
m_usedBearerType = NymeaConnection::BearerTypeEthernet;
|
||||||
|
} else if (m_networkReachabilityMonitor->availableBearerTypes().testFlag(NymeaConnection::BearerTypeWiFi)) {
|
||||||
|
m_usedBearerType = NymeaConnection::BearerTypeWiFi;
|
||||||
|
} else {
|
||||||
|
m_usedBearerType = NymeaConnection::BearerTypeMobileData;
|
||||||
|
}
|
||||||
|
qCDebug(dcNymeaConnection()) << "iOS: Assuming used bearer type:" << m_usedBearerType;
|
||||||
|
#endif
|
||||||
emit currentConnectionChanged();
|
emit currentConnectionChanged();
|
||||||
emit connectedChanged(true);
|
emit connectedChanged(true);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -141,6 +141,10 @@ private:
|
|||||||
Connection *m_preferredConnection = nullptr;
|
Connection *m_preferredConnection = nullptr;
|
||||||
|
|
||||||
QTimer m_reconnectTimer;
|
QTimer m_reconnectTimer;
|
||||||
|
|
||||||
|
#ifdef Q_OS_IOS
|
||||||
|
NymeaConnection::BearerType m_usedBearerType;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NYMEACONNECTION_H
|
#endif // NYMEACONNECTION_H
|
||||||
|
|||||||
Reference in New Issue
Block a user