Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

await in iOS device

$
0
0

Hi,

I am making an app and have an await call in my login page.
Basically the async method is run when a button is clicked and in this method it awaits a login method that verifies and sets my credentials.
This button and the login work absolutely fine in Android and in the iOS iPhone 5S (9.1) simulator.

That's great and all but somehow it doesn't work on a physical device. It seemingly returns, without returning. Here is so code to help explain. This is from the login page:

this.ButtonLogin.Clicked += async(sender, eventArgs) =>
            {
                this.AILogin.IsVisible = true;
                var vm = this.BindingContext as LoginViewModel;
                var go = await vm.Login(this.Username.Text, this.Password.Text);
                if(go)
                {
                    this.AILogin.IsVisible = false;
                    RegisterDevice();
                    //await this.Navigation.PushModalAsync(((MasterDetailPage)new RootPage()), false);
                    var hasPasswordBeenReset = Convert.ToBoolean(App.Current.Properties["BtmPasswordResetFlag"]);
                    if (hasPasswordBeenReset)
                    {
                        await this.Navigation.PushModalAsync(new NavigationPage(new ChangePasswordView()), false);
                    }
                    else
                    {
                        //RegisterDevice();
                        await this.Navigation.PushModalAsync(new NavigationPage(new MessageListView()), false);
                    }
                    //RegisterDevice();
                    //await this.Navigation.PushModalAsync(((MasterDetailPage)new RootPage()), false);
                }
                else
                {
                    this.AILogin.IsVisible = false;
                    await DisplayAlert("Authentication Failed", "Try Again", "Try Again");
                }
            };

It seems to set go as false every time the button is pressed.
The login method has several points in which to return, I've set breakpoints on all of them, and none of them are hit. It just returns false every time:
` public async Task Login(string username, string password)
{
HttpResponseMessage response = null;
if(string.IsNullOrEmpty(username) && string.IsNullOrEmpty(password))
{
//set a test default username and password
}
response = await API.PostSignInAsync(API.Authentication, username, password);
if (!response.IsSuccessStatusCode)
{
return false;
}

        JObject array;
        try
        {
            //array = response.Content.ReadAsAs
            array = response.Content.ReadAsAsync<JObject>().Result;
        }
        catch (Exception e)
        {
            return false;
        }

        var model = CreateLoginModel(array);
        return true;
    }`

In fact, even setting a break-point after response = await API.PostSignInAsync(API.Authentication, username, password); does not get hit either.
So it seems to be leaving this method prematurely and returning false.**> **

Wondering if anyone else had the same behavior or know what's going on. I also posted this in the iOS forums, but since this is technically Xamarin.Forms I asked if it should be moved here or if I should re-post it here, and still haven't gotten a reply so I'm posting it here as well.


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>