Forum Libraries, Components, and Plugins

Xamarin.Essentials: Facebook and deep linking

I'm working on a Xamarin.Forms app that will display news coming from my client's Facebook page. The app will display 2 kinds of items: the feed/posts (coming from "client_page/feed" or "client_page/posts") or the events (coming from "client_page/events")

I'm able to get the expected information for each kind of items, and to open the corresponding URL in a browser with the Browser class from Xamarin.Essentials.

For example, for a post my code looks like this:

await Xamarin.Essentials.Browser.OpenAsync(selectedNews.Url);

I'm trying to implement the deep linking to improve user experience. For this, I've added a new entry (LSApplicationQueriesSchemes) in the Info.plist file on iOS. Then, and I'm using the Launcher class from Xamarin.Essentials, but I encounter some issues.

With this code, I'm able to open the client's page in the Facebook app on Android, but not on iOS. On iOS, I only have the Facebook app that is opened on my default feed page:

await Xamarin.Essentials.Launcher.OpenAsync("fb://page/115592608462989");

With this code, I'm able to open an event of the client's page in the Facebook app on Android, but not on iOS. On iOS, I only have the Facebook app that is opened on my default feed page:

await Xamarin.Essentials.Launcher.OpenAsync("fb://event/2720519278225723");

And I didn't found any way to open a "post/feed" of the client with the deep linking: on both devices, I only get the Facebook app that is opened on my default feed page:

await Xamarin.Essentials.Launcher.OpenAsync("fb://115592608462989_3626060134082868");
await Xamarin.Essentials.Launcher.OpenAsync("fb://page/115592608462989/posts/3626060134082868");

=> Did I forgot something to make the deep linking work on iOS, as it works on Android? Is there a way to open a specific post of my client's page?

Answers

  • ColeXColeX Member, Xamarin Team Xamurai

    fb://page/… url does not work on iOS anymore , change it to fb://profile/… .


    Refer to

    https://stackoverflow.com/a/13266892/8187800
    https://stackoverflow.com/a/63658368/8187800

  • PacodosoPacodoso FRUniversity ✭✭✭

    Hi @ColeX , you're right, on iOS we need to use "profile" instead of "page" on Android.

    Now I'm able to open a dedicated post on iOS:
    await Xamarin.Essentials.Launcher.OpenAsync("fb://profile/115592608462989/posts?id=3623831304305751");

    But I didn't found a way to achieve this on Android...

  • PacodosoPacodoso FRUniversity ✭✭✭
    edited September 21

    I've found an alternative on Android to display the post, by using "fb://facewebmodal/f?href=":
    await Xamarin.Essentials.Launcher.OpenAsync("fb://facewebmodal/f?href=https://www.facebook.com/clientpage/posts/postid");

    I'm still searching another way with "fb://page" but at least it works like that...

  • ColeXColeX Member, Xamarin Team Xamurai

    If there is no common rule for all platforms , you could set different url on different platform .

         string url = null;
            if(Device.RuntimePlatform == Device.iOS)
            {
                url = "fb://profile/115592608462989/posts?id=3623831304305751";
            }
            if (Device.RuntimePlatform == Device.Android)
            {
                url = "fb://page/115592608462989";
            }
    
            await Xamarin.Essentials.Launcher.OpenAsync(url);
    
  • PacodosoPacodoso FRUniversity ✭✭✭

    Yes @ColeX it's what I did.

    But I don't understand why we can use the fb://profile/page_id/posts?id=post_id on iOS, but not the fb://page/page_id with a post_id on Android. I'm not sure that the use of fb://facewebmodal/f?href=https://www.facebook.com/page_id/posts/post_id is recommended.

Sign In or Register to comment.