We have code in our AppStudio 5 app that checks to see if the device changes network status. If the device goes offline, remove online layers and if it comes back online, add the online-only layers to the map. We use AppFramework.network Object to check for triggers of the onlineStateChanged signal. This worked perfectly in AppStudio 4.
const networkChangedStatus = () => {
if (!Networking.isOnline) {
console.log("Status changed", Networking.isOnline)
removeOnlineLineLayers()
} else {
console.log("Status changed", Networking.isOnline)
addOnlineLayersToMap()
}
}
AppFramework.network.onlineStateChanged.disconnect(networkChangedStatus)
AppFramework.network.onlineStateChanged.connect(networkChangedStatus)
Unfortunately, in AppStudio 5, this signal doesn't get triggered anymore. I know the isOnline property in Network is deprecated, so we're using Networking.isOnline, but surely the whole Network library isn't deprecated?
I also checked the Networking object's networkChanged signal and implement that to the above code into lines 11 and 12, like below.
Networking.networkChanged.disconnect(networkChangedStatus)
Networking.networkChanged.connect(networkChangedStatus)
But this networkChanged signal gets triggered too often; sitting idle while being connected to network triggers the signal every 10 seconds or so.
What's the best solution here? I want to be able to check the device's network status and make changes accordingly in my map. It seems to me like AppStudio 5 took away the ability to do this.
Any help appreciated! Thank you.
Solved! Go to Solution.
Hi @KevinCheriyan,
We actually have a simple sample app, Network Check, that demonstrates how to do this. Have it run and disconnect/reconnect to a network to see how it updates automatically. Essentially, the app determines the device isOnline by using a NetworkConfiguration component, a component that encapsulates a single access point or service network, to see if the device is connected to wifi, lan, or mobile data. In the sample, you can create a signal handler isOnlineChanged: {} to do stuff if isOnline property changes. See this doc for more details.
Hope this helps!
Trevor Frame
Hi @KevinCheriyan,
We actually have a simple sample app, Network Check, that demonstrates how to do this. Have it run and disconnect/reconnect to a network to see how it updates automatically. Essentially, the app determines the device isOnline by using a NetworkConfiguration component, a component that encapsulates a single access point or service network, to see if the device is connected to wifi, lan, or mobile data. In the sample, you can create a signal handler isOnlineChanged: {} to do stuff if isOnline property changes. See this doc for more details.
Hope this helps!
Trevor Frame
Great, the sample app helps!