编辑:可以在此处找到演示崩溃的示例项目:https://github.com/rringham/brokenazurexamforms - 您需要在以下位置设置自己的Azure App Service URL:
- src/BrokenAzureForms/Droid/Services/User/DroidUserService.cs
- src/BrokenAzureForms/iOS/Services/User/IosUserService.cs
我注意到当我尝试在Azure MobileServiceClient
验证后再使用它时,Xamarin Forms 的Navigation.PushAsync()
在Android上崩溃。这个崩溃是独立于iOS的。
这是设置-我有一个基本的NavigationPage
作为我的主应用程序页面:
MainPage = new NavigationPage(new LoginPage());
在我的LoginPage
上,我使用一个通过DependencyService
注入的类进行身份验证,在我的Android项目中执行身份验证:
private async void OnMicrosoftAccountTapped(object sender, EventArgs args)
{
IUserService userService = DependencyService.Get<IUserService>();
bool authenticated = await userService.LoginWithAzureAD();
if (authenticated)
{
await Navigation.PushAsync(new HomePage(), false);
}
}
在我的Android IUserService
实现中,我执行以下操作(基本上与Azure / Xamarin Forms教程所示的相同):
public async Task<bool> LoginWithAzureAD()
{
try
{
_user = await _client.LoginAsync(Xamarin.Forms.Forms.Context, MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory);
}
catch (Exception)
{
return false;
}
return true;
}
这里是问题发生的地方。当LoginWithAzureAD()
完成时,控件将恢复到OnMicrosoftAccountTapped()
; 然后我们调用Navigation.PushAsync()
,应用程序会崩溃,并且提供的细节非常少:
我能想到的只有Azure MobileServiceClient
在内部使用了一些相当奇怪的东西,因为如果我删除对await userService.LoginWithAzureAD()
的调用,则对Navigation.PushAsync()
的调用可以正常工作。 MobileServiceClient中的某些内容可能已经损坏,或者正在破坏Xamarin Forms中的某些内容。
有人看到过类似的情况吗?