Unity www yield return请求在编辑器中有效,但在fb app中无效

时间:2014-04-03 15:15:58

标签: c# facebook unity3d facebook-unity-sdk

目前我的问题简化了:

下面的代码在统一编辑器中工作,我已经多次检查过php,现在发送的url工作,并且它返回正确的值,但是将内容上传到要在facebook app中使用的空间中断由于某种原因,img提供了显示停止的地方。

其他一些细节:

环顾所有迹象表明它是v3.0的错误(版本I'我正在使用v4.3.3f1),但是虽然我的代码在编辑器中工作没有问题,但它赢得了#39 ;当我将其构建上传到我提供的html空间时,t继续通过yield return www请求。

在下面的块之前登录工作的当前方式是初始化FB游戏对象,登录到Facebook,检查没有错误,然后传回FB用户ID,然后传递给下面的代码 - 其按预期工作

快速编辑 - 数据库连接器包含主URL,下面的代码添加到php get的必要字符串上。

我不知道从哪里开始尝试修复它,除了如图所示更改正在显示的文本,这有助于将其分解为我的问题。

粘贴的登录屏幕图像:http://i.imgur.com/ti2YLrW.png?1

代码:

using UnityEngine;

using System.Collections;

using System;

public class ConnectToDataBase : MonoBehaviour {

    public bool bDatabaseConnected = false;
    public bool bConnectionFailed = false;

    public string sFacebookID;
    public WWWForm wwwForm;

    public void vStartConnection()
    {
        var text = GameObject.FindGameObjectWithTag ("Other");

        text.guiText.text = "Login : connectToDatabase: prepping query";

        //call databasequeries and get sDBConnect
        string sConnectPhp = GameObject.FindGameObjectWithTag("DBConnector").GetComponent<DatabaseQueries>().sDBConnect;

        //now ready the url with the necessary code for php's get, and the FacebookID
        string url = sConnectPhp + "?UserID=" + sFacebookID;

        text.guiText.text = "Login : connectToDatabase: url being sent:\n" + url;

        WWW wwwGet = new WWW(url);

        text.guiText.text = "Login : connectToDatabase: wwwGet created";

        text.guiText.text = "Login : connectToDatabase: starting coroutine";
        StartCoroutine(Connect(wwwGet));
    }

    IEnumerator Connect(WWW www)
    {
        var text = GameObject.FindGameObjectWithTag("Other");
        text.guiText.text = "Login : connectToDatabase: coroutine started - sending www request";

        yield return www;

        text.guiText.text = "Login : connectToDatabase: wwwGet yield return";

        string sTemp = www.text;

        if(www.error == null)
        {
            text.guiText.text = "Login : connectToDatabase: wwwGet has not errored";

            string newString = sTemp.ToString();
            int newInt = Convert.ToInt32(newString);

            //print (newString);
            text.guiText.text = "Login : connectToDatabase: checking wwwGet return as int";

            if(newInt == 0)
            {
                //if successfully connected set to true
                print ("connectToDatabase: olduser successful");
                text.guiText.text = "Login : connectToDatabase: olduser successful";

                bDatabaseConnected = true;
                yield break;
            }
            else if(newInt == 1)
            {
                //if successfully connected set to true
                print ("connectToDatabase: newuser successful");
                text.guiText.text = "Login : connectToDatabase: newuser successful";

                bDatabaseConnected = true;
                yield break;
            }
            else if(newInt == 2)
            {
                //game connection has failed
                print ("connectToDatabase: failed");
                text.guiText.text = "Login : connectToDatabase: failed";
                bDatabaseConnected = false;
                bConnectionFailed = true;
                yield break;
            }
            else
            {
                text.guiText.text = "Login : connectToDatabase: php did not return a 0/1/2 value";
            }
        }
        else
        {
            //game connection has failed
            print ("connectToDatabase: failed");
            text.guiText.text = "Login : connectToDatabase: wwwGet has errored:\n" + www.error;

            bDatabaseConnected = false;
            bConnectionFailed = true;
            yield break;
        }

        text.guiText.text = "Login : connectToDatabase: wwwGet if statement skipped entirely";
    }
}

1 个答案:

答案 0 :(得分:1)

在浏览器中运行时有不同的规则。如上所述,here应用程序处于沙盒模式,因此您需要添加crossdomain策略(我知道该链接适用于Flash Player,但适用相同的原则)。

最后,您需要保存在Web服务器根目录中 crossdomain.xml 文件中的此类内容。

<?xml version="1.0"?>
<cross-domain-policy>
 <allow-access-from domain="*" secure="false"/>
</cross-domain-policy>