question

mouhibbahri-7194 avatar image
0 Votes"
mouhibbahri-7194 asked RobCaplan edited

Deep linking opens the app but doesn't open the link xamarin forms

When I tap on the link, the app opens but navigates to MainPage instead of reading the url and opening the corresponding page. I tried to click on the link again ,when the app is already opened, and it worked! It seemed like the constructor

public App(){ InitializeComponent(); MainPage = new NavigationPage(new MainPage ()); }

works first when the app is opened instead of



 protected override async void OnAppLinkRequestReceived(Uri uri)
 {
     base.OnAppLinkRequestReceived(uri);
     MainPage = new NavigationPage(new Page1(""));
 }

How do I set the priority for OnAppLinkRequestReceived() before App()?



dotnet-xamarin
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

It seemed like the constructor ... works first when the app is opened instead of

Hi, @mouhibbahri-7194 I created a basic demo to test the function, the corresponding page is correctly opened. The constructor method works first indeed, then the OnAppLinkRequestReceived is called if the app is started via a link. There is nothing wrong with the step. Please try to add a breakpoint to the 'OnAppLinkRequestReceived' event to check if it is called. And do you add some code to the App's other lifecycle method such as 'OnStart' event.

public partial class App : Application
{
    public App()
    {
        InitializeComponent();

        MainPage = new NavigationPage(new MainPage());
    }
    protected override void OnAppLinkRequestReceived(Uri uri)
    {
        base.OnAppLinkRequestReceived(uri);

        MainPage = new NavigationPage(new TestPage());
    }
}
0 Votes 0 ·

Yes I have this:

 protected async override void OnStart()
     {
           PermissionsModel permissionModel = new PermissionsModel();
           await permissionModel.CheckAndRequestStoragePermission();
        
     }

and I definitely can't try breakpoints because my problem is that the 'OnAppLinkRequestReceived ' is called only when the app is open and not closed(I can't debug it when the app is closed right?)



0 Votes 0 ·

1 Answer

mouhibbahri-7194 avatar image
0 Votes"
mouhibbahri-7194 answered

I think the problem was that in 'OnAppLinkRequestReceived ' I had a load of tasks to do like reading the data and connecting with the database so probably the app just navigates to the mainpage which is strange to be honest... I tried to do less work in that event in App.xaml.cs and just pass the link through parameters to the corresponding page and letting it do the tasks instead.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.