Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solution for navigation from a service #1128

Closed
mo-kml opened this issue Jul 26, 2017 · 4 comments
Closed

solution for navigation from a service #1128

mo-kml opened this issue Jul 26, 2017 · 4 comments

Comments

@mo-kml
Copy link

mo-kml commented Jul 26, 2017

hi there
im using odata for my server integration and xamarin forms for my client side.i have a service that passes odata context to another view models. i wanna sign out the user when odata response be unAuthorize error. but i have a problem. i wanna navigate user to login page from my service. but i not able to do this. what solution do you suggest to make this right?
this is what i want to do but without a view model i cant do that.

private void ServerContext_ReceivingResponse(object sender, ReceivingResponseEventArgs e)
{
if (!e.ResponseMessage.Headers.Any(h => h.Key == "X-CorrelationId"))
{
_dialogService.DisplayAlertAsync("Authentication Failed", "Authentication Failed.Please Login again", "Ok");
_navigationService.NavigateAsync(nameof(CompanyLoginView));
}
}

Actually ive tries MessagingCenter of xamarin to do so but it didnt work out.
I sent a message from my service that you have been logout

private void ServerContext_ReceivingResponse(object sender, ReceivingResponseEventArgs e)
{
if (!e.ResponseMessage.Headers.Any(h => h.Key == "X-CorrelationId"))
{
MessagingCenter.Send(this, "Logout");
}
}

and in constructor of my view model i navigate to another page but navigation didn't work. also IPageDialogService also didnt work and throw an exception.

MessagingCenter.Subscribe(this, "Logout",(sender) =>
{
_navigationService.NavigateAsync("CompanyLoginView");
_dialogService.DisplayAlertAsync("Error", "Please select void reason", "Ok");
});

  • Platform: Xamarin forms shared project
  • Prism version: 6.3.0
  • Xamarin version (if applicable): 2.3.4.247
@brianlagunas
Copy link
Member

You shouldn't try to navigate within the service. Your service should provide you with a response and you navigate after receiving that response in your ViewModel.

@mo-kml
Copy link
Author

mo-kml commented Jul 30, 2017

@brianlagunas actually i am doing this. i`m using MessagingCenter of Xamarin forms to send a message to my ViewModel that my authentication has been expired. but even when i use MessageCenter and navigate from my ViewModel it wont navigate or even not display alert with dialogService

@brianlagunas
Copy link
Member

brianlagunas commented Jul 31, 2017

Then you have a different problem in your code. Unfortunately, there is not enough detail or information provided to help you pin point the issue. I suggest debugging every aspect of that view to make sure everything functions properly prior to invoking it with a message.

@lock
Copy link

lock bot commented Jan 30, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants