【问题标题】:Web browser navigation crash in wp8wp8中的Web浏览器导航崩溃
【发布时间】:2014-12-15 17:22:29
【问题描述】:

我正在开发 windows phone 应用程序。在这个应用程序中我需要与foursquare集成,所以我在网络浏览器中加载了foursqare的url。网络浏览器加载了四方登录页面,当我输入登录名时它工作正常详细信息并按 Enter,然后我将隐藏 Web 浏览器并在来自服务的列表中显示数据。10-15 秒后应用程序崩溃。此崩溃不会在模拟器中看到,它仅发生在手机(lumia 520)中。 lumia 920 很好用

我的 xaml 代码

                  <Grid Grid.ColumnSpan="2" Name="browserGrid" Visibility="Visible">
                    <phone:WebBrowser x:Name="foursquareBrowser" IsScriptEnabled="True" VerticalAlignment="Top" Height="720"   />
            <!--<ProgressBar x:Name="progressBar" IsIndeterminate="True" Visibility="Collapsed"/>-->


                </Grid>

浏览器.cs

         void foursquareBrowser_Loaded(object sender, RoutedEventArgs e)
    {
        try
        {
            foursquareBrowser.Navigate(new Uri("https://foursquare.com/oauth2/authorize?client_id=EYXOAIOMY3BNFR3DPB4SCK1JGR1J3FKDES4O5RGE3DDDM5WI&response_type=code&redirect_uri=http://www.visitabudhabi.ae"));
           foursquareBrowser.Navigating+=foursquareBrowser_Navigating;
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }



  private void foursquareBrowser_Navigating(object sender, NavigatingEventArgs e)
    {
        try
        {
            if (e.Uri.OriginalString.Contains("https://foursquare.com/login"))
            {
           foursquareBrowser.Navigate(new Uri("https://foursquare.com/oauth2/authorize?client_id=EYXOAIOMY3BNFR3DPB4SCK1JGR1J3FKDES4O5RGE3DDDM5WI&response_type=code&redirect_uri=http://www.visitabudhabi.ae"));
            }
            else if (e.Uri.OriginalString.Contains("code="))
            {

                     uri = e.Uri.OriginalString.ToString().Split(new string[] { "code=" }, StringSplitOptions.None).Last();
                    uri = uri.Remove(uri.Length - 4);
                      WebClient wc = new WebClient();
                    string postData = string.Empty;
                    wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
                    wc.UploadStringAsync(new Uri("https://foursquare.com/oauth2/access_token?client_id=EYXOAIOMY3BNFR3DPB4SCK1JGR1J3FKDES4O5RGE3DDDM5WI&client_secret=1ROOV3FGYQZMVXV0TB1BRMHRIKB3RHI224M2NV0YFC0XXC1U&grant_type=authorization_code&redirect_uri=http://www.visitabudhabi.ae&code=" + uri, UriKind.Absolute), "POST", postData.ToString());
                    wc.UploadStringCompleted += new UploadStringCompletedEventHandler(wc1_UploadStringCompleted);
                    foursquareBrowser.Navigating-=foursquareBrowser_Navigating;  

                }

            }



        }
        catch (Exception ex)
        {

            MessageBox.Show(ex.Message);
        }



    }

没有任何调试信息就崩溃了。

【问题讨论】:

  • 在 Lumia 520 上调试时异常说明了什么?
  • 你有没有找到任何解决方案?我在 WP8.1 上遇到了类似的问题

标签: windows-phone-8


【解决方案1】:

检查这一行的语法

foursquareBrowser.Navigate(new Uri("https://foursquare.com/oauth2/authorize?  client_id=EYXOAIOMY3BNFR3DPB4SCK1JGR1J3FKDES4O5RGE3DDDM5WI&response_type=code&redirect_uri=http://www.visitabudhabi.ae"));

您似乎错过了上述语法UriKind.RelativeOrAbsolute

 foursquareBrowser.Navigate(new Uri("https://foursquare.com/oauth2/authorize?client_id=EYXOAIOMY3BNFR3DPB4SCK1JGR1J3FKDES4O5RGE3DDDM5WI&response_type=code&redirect_uri=http://www.visitabudhabi.ae",UriKind.RelativeOrAbsolute));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多