Xamarin表示iOS应用程序无法使用Azure移动服务Active Directory身份验证

时间:2017-03-09 23:08:43

标签: xamarin.forms azure-mobile-services azure-authentication

我创建了一个Xamarin Forms应用程序,该应用程序使用Azure Active Directory对Azure移动服务进行身份验证。这适用于我的WinPhone应用程序,但它不适用于iOS设备。它适用于iOS模拟器,但不适用于实际设备。我已将其缩小到导致应用程序在设备上崩溃的确切行。它位于AppDelegate.cs文件中,它是" App.Init(this)"线。它不会抛出任何错误(至少不是我能看到的)。它在模拟器中运行良好,它可以在设备上进行部署和安装。但是,当您单击设备上的应用程序来运行它时,它会显示启动画面,然后只需退出。

我遵循了https://docs.microsoft.com/en-us/azure/app-service-mobile/app-service-mobile-xamarin-forms-get-started-users的文档,这篇文章非常复杂,其他一切都有效。

任何人都可以了解为什么" App.Init(this)"会在iOS AppDelegate.cs文件中失败吗?它正在实施IAuthenticate(完整代码如下)

[Register("AppDelegate")]
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate, IAuthenticate
{
    //
    // This method is invoked when the application has loaded and is ready to run. In this 
    // method you should instantiate the window, load the UI into it and then make the window
    // visible.
    //
    // You have 17 seconds to return from this method, or iOS will terminate your application.
    //
    public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    {
        global::Xamarin.Forms.Forms.Init();
        Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init();

        //App.Init(this);  //If I uncomment this line, the app crashes. Leaving this line commented, the app doesn't every do the login/authentication.

        LoadApplication(new App());

        return base.FinishedLaunching(app, options);
    }
    // Define a authenticated user.
    private MobileServiceUser user;

    public async Task<bool> Authenticate()
    {
        var success = false;
        var message = string.Empty;
        try
        {
            // Sign in with Facebook login using a server-managed flow.
            if (user == null)
            {

                user = await FormDataManager.DefaultManager.CurrentClient
                    .LoginAsync(UIApplication.SharedApplication.KeyWindow.RootViewController,
                    MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory);

                if (user != null)
                {
                    message = string.Format("You are now signed-in as {0}.", user.UserId);
                    success = true;
                }
            }
        }
        catch (Exception ex)
        {
            message = ex.Message;
        }

        // Display the success or failure message.
        UIAlertView avAlert = new UIAlertView("Sign-in result", message, null, "OK", null);
        avAlert.Show();

        return success;
    }


}

1 个答案:

答案 0 :(得分:0)

azure docs将接口分离为自己的依赖服务,但这看起来不太清楚。

很高兴你把它整理好了。要提供其他参考,请查看http://aka.ms/zumobook

上的书籍