Reputation: 838
I'm working on a Xamarin.Forms app that uses Firebase Authentication. In order to make Firebase work, I have to create two different platform-specific files (iOS and Android) to process the Authentication tasks (like CreateNewUser and Login). I have a Xamarin.Forms page called "Payment Page" that asks a user to enter their e-mail and password, and submitting this page triggers the DependencyService to create the user account. On the Payment Page, I also have a small window that will appear if something goes wrong with the account creation process (specifically in this case, if a duplicate e-mail already exists in the Auth database).
My question is, if one of the Dependency files for iOS or Android catches a 'ERROR_EMAIL_ALREADY_IN_USE', how can I set the error dialog on the Payment Page to show (in other words, set its 'isVisible' property to 'true'). I've tried a number of things but so far cannot seem to reference elements in the PaymentPage (a Xamarin.Forms page) from the Xamarin.iOS Authentication page.
My Dependency code is as follows:
public void CreateNewUser(string email, string password, System.Collections.Specialized.NameValueCollection userData)
{
Auth.DefaultInstance.CreateUser(email, password, HandleAuthDataResultHandler);
}
async void HandleAuthDataResultHandler(AuthDataResult authResult, Foundation.NSError error)
{
if(error.UserInfo["error_name"].ToString() == "ERROR_EMAIL_ALREADY_IN_USE")
{
//What goes here to modify the Xamarin.Forms page??
}
else { }
}
Upvotes: 0
Views: 128
Reputation: 367
MessagingCenter might be a good way to go https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/messaging-center
You can suscribe your viewmodel and post a message from the handler with the result.
Upvotes: 1
Reputation: 89129
in your XAML code behind
try {
// call your dependency service
} catch (Exception ex)
{
// update the UI
}
then in your DependencyService method, it should throw an exception when an error condition occurs
Upvotes: 1