dotnetco.de

PushAsync is not supported globally on iOS, please use a NavigationPage

Ever ran into this problem? Easiest fix: Check your App.xaml.cs. Did you set your MainPage directly like MainPage = new StartPage(); ? If so, just change it to MainPage = new NavigationPage(new StartPage());

But it also appears where you cannot change it easily, e.g. if you are on a carousel page and want to open a new page using await Navigation.PushAsync(new myPage());

So instead of using PushAsync, the easiest solution is to use PushModalAsync, like

await Navigation.PushModalAsync(new myPage()); 

Now you might run into another problem: In some cases, myPage might be called via PushAsync and in some cases via PushModalAsync. So if you have a Back-Button on myPage, it might call PopAsync or PopModalAsync.

Check whether to call Pop or PopModal

To find out whether you have to call PopAsync or PopModalAsync, you only have to check the Navigation Stack. If your page is opened as modal, no navigation stack contains 0 elements. Additionally you could also Navigation.ModalStack  to see whether it’s a modal window.

public async void OnHeaderBackImageTapped(object sender, EventArgs e) 
{     
   var stack = Navigation.NavigationStack;     
   if (stack.Count == 0)
         await Navigation.PopModalAsync();     
   else
         await Navigation.PopAsync(); 
}

Leave a Comment