简体   繁体   中英

Facebook SDK for Unity, FB.Feed error on iOS

This is a very odd issue we're having. When using the Facebook SDK in Unity and calling FB.Feed after logging in the Facebook dialog pops up momentarily and then closes back to the game screen. This only happens on the iOS version of our game, and only happens the very first time that we try to post up to Facebook after installing. Every subsequent time works perfectly fine.

I've not been able to find any information on this and would greatly appreciate any help.

public IEnumerator ShareToFacebook ()
{
    if(!FB.IsLoggedIn)
    {
        FB.Login("email", LoginCallback);
        yield return FB.IsLoggedIn;
    }

    FB.Feed( link: linkParameterSet, linkName: nameParameterSet, linkCaption: captionParameterSet, linkDescription: GetDisplayTextFB(), picture: pictureParameterSet);
}

This is the C# code I'm using, all the parameters for FB.Feed are strings set elsewhere.

I usually do it this way:

public delegate void OnShare(bool success);
static OnShare onShareCallback;
public static void Share(string link, string linkName, string linkCaption, string linkDescription, string picture, string actionName, string actionLink, OnShare callback)
{
    onShareCallback = callback;
    FB.Feed(
        toId: null,
        link: link,
        linkName: linkName,
        linkCaption: linkCaption,
        linkDescription: linkDescription,
        picture: picture,
        mediaSource: null, 
        actionName: actionName,
        actionLink: actionLink,
        reference: null,
        properties: null,
        callback: ShareCallback
    );
}

public static void ShareCallback(FBResult result)
{
    if (!String.IsNullOrEmpty(result.Error))
    {
        if (onShareCallback != null)
        {
            onShareCallback(false);
            onShareCallback = null;
        }
    }
    else
    {
        if (onShareCallback != null)
        {
            onShareCallback(true);
            onShareCallback = null;
        }
    }
}

It's static, you can use it everywhere without even attaching the script on a game object.

I call it this way:

MyFacebook.Share(link, linkName, linkCaption, linkDescription, picture, actionName, actionLink, ProcessFacebookShare);


void ProcessFacebookShare(bool success)
{
    if(success)
    {
        Debug.Log("Successfully shared!");
    }
    else
    {
        Debug.Log("There was a problem with facebook sharing");
    }
}

Hope it helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM