CrossGeeks / FacebookClientPlugin

Facebook Client Plugin for Xamarin iOS and Android
MIT License
106 stars 32 forks source link

Facebook GameRequestDialog #28

Closed treidio closed 5 years ago

treidio commented 6 years ago

Hi,

sorry I don't know how to do pull requests, and besides my code is so amateur. :)

For IOS i got the game request dialog working, sharing it back with the project.. I don't get the alert in the destination account, but expect that's because my app isn't published or approved.

Presented at your own risk..

FacebookClientManager.cs ~line 216

    public async Task<FacebookResponse<Dictionary<string,object>>> GameRequestDialog(string message, string title = "")
    {
        _shareTcs = new TaskCompletionSource<FacebookResponse<Dictionary<string, object>>>();
        Dictionary<string, object> parameters = new Dictionary<string, object>()
        {
            {"message",message},

        };

        if (!string.IsNullOrEmpty(title))
        {
            parameters.Add("title", title);
        }
        return await PerformAction(RequestGameRequestDialog, parameters, _shareTcs.Task, FacebookPermissionType.Read, new string[] { "email" });
    }

~line 487

    void RequestGameRequestDialog(Dictionary<string, object> paramsDictionary)

    { 
        if (paramsDictionary != null && paramsDictionary.ContainsKey("message"))
        {
            string Message = paramsDictionary["message"] as string;
            GameRequestContent request = new GameRequestContent();
            request.Message = Message;

            if (paramsDictionary.ContainsKey("title"))
            {
                request.Title = $"{paramsDictionary["title"]}";
            }

            GameRequestDialog dialog = new Facebook.ShareKit.GameRequestDialog();
            var window = UIApplication.SharedApplication.KeyWindow;
            dialog.Content = request;
            dialog.Show();
        }

    }

iFacebookClient.cs ~line 121 Task<FacebookResponse<Dictionary<string, object>>> GameRequestDialog(string message, string title = "");

Called by

await CrossFacebookClient.Current.GameRequestDialog("A message", "a Title");

treidio commented 6 years ago

Similar attempt for android.

unsure about the bolded line, I'm unsure if the sharecallback will work. The Dialog is a Xamarin.Facebook.Share.Widget so maybe it will.

line 352 insert this

        public async Task<FacebookResponse<Dictionary<string, object>>> GameRequestDialog(string message, string title = "")
        {
            _shareTcs = new TaskCompletionSource<FacebookResponse<Dictionary<string, object>>>();
            Dictionary<string, object> parameters = new Dictionary<string, object>()
            {
                {"message",message},

            };

            if (!string.IsNullOrEmpty(title))
            {
                parameters.Add("title", title);
            }
            return await PerformAction(RequestGameRequestDialog, parameters, _shareTcs.Task, FacebookPermissionType.Read, new string[] { "email" });
        }

line 756, this..

        void RequestGameRequestDialog(Dictionary<string, object> paramsDictionary)

        {
            if (paramsDictionary != null && paramsDictionary.ContainsKey("message") && paramsDictionary.ContainsKey("title"))
            {
                var activity = Android.App.Application.Context as Activity;
                string Message = paramsDictionary["message"] as string;
                string Title = "";
                if (paramsDictionary.ContainsKey("title"))
                {
                    Title = $"{paramsDictionary["title"]}" as string; ;
                }
                var content = new GameRequestContent.Builder().
                    SetTitle(Title).
                    SetMessage(Message).
                    Build() as GameRequestContent;

                GameRequestDialog dialog = new GameRequestDialog(activity);
                **dialog.RegisterCallback(mCallbackManager, shareCallback);**
                dialog.Show(content);
            }

        }
rdelrosario commented 5 years ago

Feature added to beta version:

https://www.nuget.org/packages/Plugin.FacebookClient/2.1.16-beta