Search code examples
c#iosxamarin.formsapplinks

xamarin forms app link - open PCL view from ios app delegate


In a Xamarin Forms cross platform app I can open the app from an external email app link.

It opens in android just fine, by adding an intent to the manifest, then within the activity which starts, I create another intent to fire the main activity

public class AppLinkActivity : Activity
{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        string code = null;
        if (Intent.Data.Query != null)
        {
            code = Intent.Data.Query.Substring(Intent.Data.Query.LastIndexOf('=') + 1);
        }

        if (Intent.Data != null)
        {
            var uri = Intent.Data;
            if (uri != null)
            {
                Intent i = new Intent(this, typeof(MainActivity));
                i.AddFlags(ActivityFlags.ReorderToFront);
                i.PutExtra("code", code);
                i.PutExtra("flag", true);
                this.StartActivity(i);
            }
        }
        this.FinishActivity(0);
    }
}

In ios, the applink triggers the override of OpenUrl in the app delegate, but I'm not sure how to navigate to a particular PCL page from here, what happens is the app opens at it's last open page

public override bool OpenUrl(UIApplication app, NSUrl url, string sourceApp, NSObject annotation)
{
    string _uri = url.ToString();
    string code = _uri.Substring(_uri.LastIndexOf('=') + 1);

    LoadApplication(new App(true, code));
    return true;
}

Can anyone point me in the right direction with this? All I really need to do is, from the OpenUrl method, navigate to a view within the PCL


Solution

  • for anyone interested, I sorted this by replacing

    LoadApplication(new App(true, code));
    

    with

    App.Current.MainPage = enterPin();
    

    which calls

    public Page enterPin()
     {
           return new EnterPinPage(SimpleIoc.Default.GetInstance<ISecureStorage>(), code, 1);
     }