facebook登录按钮sdk在c#崩溃的应用程序中

Nip*_*pun 5 windows-phone-8 facebook-sdk-3.0

我需要一个小帮助,我已经为Windows Phone 8创建了一个小的physioit应用程序.

我在我的xaml文件中添加了facebookclient loginbutton.现在,当我的手机中没有数据连接,当我运行代码时,它会让我TargetInvocationException和我的应用程序崩溃.

这是我得到的例外 -

innerException 
{Facebook.WebExceptionWrapper: The remote server returned an error: NotFound. --->
      System.Net.WebException: The remote server returned an error: NotFound.
 at System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
 at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClasse.<EndGetResponse>b__d(Object sendState)
 at System.Net.Browser.AsyncHelper.<>c__DisplayClass1.<BeginOnUI>b__0(Object sendState)
--- End of inner exception stack trace ---}           

System.Exception     {Facebook.WebExceptionWrapper}
Run Code Online (Sandbox Code Playgroud)

我怎么能抓住这个例外?

我正在使用facebook sdk创建loginbutton

这是代码片段

<facebookControls:LoginButton
    x:Name="loginButton"
    Grid.Row="2"
    Margin="5"
    HorizontalAlignment="Right"
    FetchUserInfo="True"      
    ApplicationId="xxxxxx" 
    SessionStateChanged="OnFacebookSessionStateChanged"
    UserInfoChanged="OnFacebookUserInfoChanged"
    AuthenticationError="LoginButtonAuthenticationError" />
Run Code Online (Sandbox Code Playgroud)

你能帮帮我吗?

小智 0

您可以使用 NetworkInterface 检查数据连接是否可用,然后允许登录按钮执行其操作。

像这样的东西..

if(System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
//Allow login button
else
//Message user - no internet connection
Run Code Online (Sandbox Code Playgroud)