Showing posts with label Connectivity. Show all posts
Showing posts with label Connectivity. Show all posts

Wednesday, September 23, 2015

How to get connection and carrier information in Windows Phone 8.1 Runtime

Problem:

I have been using the MVVMCross Connectivity plugin for a project.  I went to upgrade the
WP UI to windows phone 8.1 and hit issues immediately.  This is due to the Inversion of Control
layer for Windows Phone in the plugin.  The plugin is using deprecated functionality mainly the DnsEndPoint as part of the Microsoft.Phone.Net namespace.  This is how the plugin is determining if a phone is connected. This requires the change be applied for IsPingReachable method in the Connectivity class in the Windows Phone UI layer for the plugin.

Solution:

Update the connectivity library for MVVMCross with this info

1.) Test for internet connection on Phone

  //Get the Internet connection profile
    string connectionProfileInfo = string.Empty;
    try {
        ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();

        if (InternetConnectionProfile == null) {
            NotifyUser("Not connected to Internet\n");
        }
        else {
            connectionProfileInfo = GetConnectionProfile(InternetConnectionProfile);
            NotifyUser("Internet connection profile = " +connectionProfileInfo);
        }
    }
    catch (Exception ex) {
        NotifyUser("Unexpected exception occurred: " + ex.ToString());
    }

2.) Get Connectivity properties for Windows Phone 8.1

using Windows.Networking.Connectivity;

/// <summary>
/// Detect the current connection type
/// </summary>
/// <returns>
/// 2 for 2G, 3 for 3G, 4 for 4G
/// 100 for WiFi
/// 0 for unknown or not connected</returns>
private static byte GetConnectionGeneration()
{
    ConnectionProfile profile = NetworkInformation.GetInternetConnectionProfile();
    if (profile.IsWwanConnectionProfile)
    {
        WwanDataClass connectionClass = profile.WwanConnectionProfileDetails.GetCurrentDataClass();
        switch (connectionClass)
        {
            //2G-equivalent
            case WwanDataClass.Edge:
            case WwanDataClass.Gprs:
                return 2;

            //3G-equivalent
            case WwanDataClass.Cdma1xEvdo:
            case WwanDataClass.Cdma1xEvdoRevA:
            case WwanDataClass.Cdma1xEvdoRevB:
            case WwanDataClass.Cdma1xEvdv:
            case WwanDataClass.Cdma1xRtt:
            case WwanDataClass.Cdma3xRtt:
            case WwanDataClass.CdmaUmb:
            case WwanDataClass.Umts:
            case WwanDataClass.Hsdpa:
            case WwanDataClass.Hsupa:
                return 3;

            //4G-equivalent
            case WwanDataClass.LteAdvanced:
                return 4;

            //not connected
            case WwanDataClass.None:
                return 0;

            //unknown
            case WwanDataClass.Custom:
            default:
                return 0;
        }
    }
    else if (profile.IsWlanConnectionProfile)
    {
        return 100;
    }
    return 0;
}
 




Source

  1. https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh452991.aspx
  2. http://stackoverflow.com/questions/24003786/how-to-get-connection-and-carrier-information-in-windows-phone-8-1-runtime

Thursday, December 4, 2014

Xamarin Build server with address 192.168.x.x is too old to be used with this version of Xamarin.iOS extension

Problem:

In Visual Studio, I try to connect to the Xamarin Build Host on my Mac.  VS flags an error when I try to compile.  This event occurs when I try to connect to the Build Host.  The error states that my Mac version of Xamarin is to old. 

Try 1:
My obvious conclusion was to update the Mac system to the latest version of Xamarin and try again.
I did this and it did not work.  I installed the update and rebooted the Mac.  I tried to connect from Visual Studio and still got the error.

Try 2:
My next thought was to update my build box which hosts Visual Studio.  I did the update to the most current version of Xamarin Studio which will include the Build Host.  The error was still present following install and reboot.  This is really getting annoying.

Solution:

I took a step back and looked at my Windows dev system and ignored the error message from Xamarin.  I looked at the log files and noted that there was mention of the machine not being reachable.  This got me wondering and I began looking at Network issues. 

I opened up IE > Internet Options > Connections > LAN Settings

There was the problem!!!  The Proxy server check box was selected.  This meant that all my traffic was going through a static connection and not using DHCP.

Fix was to unselect Use Proxy Server checkbox and Select the Automatically detect settings checkbox.

Notes:
The problem with this error is that error message does not alert you to the fact that it is a networking issue.  I had to look at the logs to determine the issue.