Your code is notified of changes in the overall connectivity state of the Xbox One console through the Windows::Networking::Connectivity::NetworkInformation::NetworkStatusChanged event. Your code should monitor this event to detect general connectivity changes.
To find the new state of connectivity, call GetNetworkConnectivityLevel on the current ConnectionProfile. The NetworkConnectivityLevel on Xbox One indicates whether the console has a valid connection to Xbox Live by setting the XboxLiveAccess connectivity level.
When your code detects that network connectivity is not present, it should automatically disable service calls to Xbox services and your own title’s services, and update the game UI and functionality accordingly. Once network connectivity is restored, your code can resume normal service usage.
Note that when network conditions change, multiple NetworkStatusChanged events can be signaled. Your code must be written to handle multiple rapid events correctly, and to handle null ConnectionProfile values correctly.
Note The NetworkStatusChanged event can also occur during normal runtime if no actual changes to the NetworkConnectivityLevel occurred. This can be caused by changes to the underlying network layers that have no impact on the title connectivity level. Your code should check the NetworkConnectivityLevel after every event and filter events that had no impact.
The following code sample shows the basics of handling the NetworkStatusChanged event.
Windows::Networking::Connectivity::NetworkInformation::NetworkStatusChanged +=
ref new Windows::Networking::Connectivity::NetworkStatusChangedEventHandler(
[this] ( Platform::Object^ )
{
auto connectionLevel = Windows::Networking::Connectivity::NetworkConnectivityLevel::None;
auto internetProfile = Windows::Networking::Connectivity::NetworkInformation::GetInternetConnectionProfile();
if (internetProfile != nullptr)
{
connectionLevel = internetProfile->GetNetworkConnectivityLevel();
}
if (connectionLevel != Windows::Networking::Connectivity::NetworkConnectivityLevel::XboxLiveAccess)
{
// No internet connectivity
// Update game state accordingly
}
else
{
// Network connectivity restored
// Update game state accordingly if in invalid state
}
});