我正在开发windows phone app。在这个应用程序中我需要与foursquare集成,所以我在网页浏览器中加载了foursqare的网址.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>
browser.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);
}
}
没有任何调试信息就崩溃了。
答案 0 :(得分:0)
检查此行的语法
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));