修复www Xcode iPhone

时间:2015-10-16 12:02:36

标签: unity3d

我有这个脚本用于登录注册。在Unity中,它工作正常,但在iPhone上发布不起作用 - 可能出错?

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class LoginSystem : MonoBehaviour {

public enum lMode{login,register};
public lMode LoginMode;

public GUISkin skin;
//login
private string user = "";
private string pass = "";
private int    boolstatus;
//register
private string name = "";
private string password = "";
private string email = "";

private string Log;
public Texture LogTexture;

public string sceneMap;
[System.Serializable]
public class LoginParameters{
    public Text LoginString;
    public Text PassString;
    public Toggle Remember;
}
[System.Serializable]
public class RegisterParameters{
    public Text UserString;
    public Text PassString;
    public Text EmailString;
}

public LoginParameters LP;
public RegisterParameters RP;

public static int score;
public static string userName;

private string[] ListStrings;

public GameObject LoginM;   
public GameObject RegisM;

public Text logText;

void Start () {
    boolstatus = PlayerPrefs.GetInt("bs");
    if (boolstatus == 1) {
        Debug.Log("BoolStatus = 1");
        LP.Remember.isOn = true;
    }else{
        LP.Remember.isOn = false;
    }
    if (LP.Remember.isOn == true) user = PlayerPrefs.GetString ("login");
    Debug.Log ("LP.Remember.isOn == true");
}

void Update () {
    logText.text = Log;
    if (LoginMode == lMode.login) {
        Debug.Log("LoginMode == lMode.login");
        LoginM.SetActive(true);
        RegisM.SetActive(false);
    }else if(LoginMode == lMode.register){
        LoginM.SetActive(false);
        RegisM.SetActive(true);
    }
    if (LP.Remember.isOn == true) {
        Debug.Log("LP.Remember.isOn == true");
        PlayerPrefs.SetString("login",user);
        boolstatus = 1;
        PlayerPrefs.SetInt("bs",boolstatus);
    }else{
        boolstatus = 0;
        PlayerPrefs.SetInt("bs",boolstatus);
    }

}
void OnGUI(){
    GUI.skin = skin;
}
void RequestRegister(){
    name  = RP.UserString.text;
    email = RP.EmailString.text;
    password = RP.PassString.text;
    if (name.Length < 1) {
        Debug.Log("name.Length < 1");
        Log = "Preencha o campo do Usuário.";
    }else{
        if(email.Length < 1){
            Debug.Log("email.Length < 1");
            Log = "Preencha o campo do E-Mail.";
        }else{
            if(password.Length < 1){
                Debug.Log("password.Length < 1");
                Log = "Preencha o campo da Senha.";
            }else{
                WWWForm register = new WWWForm();
                register.AddField("user",name);
                register.AddField("pass",password);
                register.AddField("email",email);
                WWW w = new WWW("http://nfx.comuv.com/register.php",register);
                StartCoroutine(RequestRegisterInformations(w));
            }
        }
    }
}
void RequestLogin(){
    user = LP.LoginString.text;
    pass = LP.PassString.text;
    Log = "";
    if (user.Length < 1) {
        Debug.Log("user.Length < 1");
        Log = "Preencha o campo do usuario";
    }else{
        if(pass.Length < 1){
            Debug.Log("pass.Length < 1");
            Log = "Preencha o campo da senha";
        }else{
            WWWForm login = new WWWForm();
            login.AddField("user",user);
            login.AddField("pass",pass);
            WWW w = new WWW("http://nfx.comuv.com/Login.php",login);
            StartCoroutine(RequestLoginInformations(w));
        }
    }
}
 IEnumerator RequestLoginInformations(WWW w){
    yield return w;
    if (w.error == null) {
        Debug.Log("w.error == null");
        Log = w.text;
        ListStrings = w.text.Split(';');
        if(ListStrings[0] == "Bem vindo"){
            Debug.Log("ListStrings[0] == Bem vindo");
            Log = "Seja " + ListStrings[0] + " " + ListStrings[1] +" ";
            userName = ListStrings[1];
        }
        if(ListStrings[0] == "Bem vindo"){
            Debug.Log("Bem vindo");
            Application.LoadLevel(sceneMap);
        }
    }
}
 IEnumerator RequestRegisterInformations(WWW w){
    yield return w;
    if (w.error == null) {
        Debug.Log("w.error == null");
        Log = w.text;
        if(Log == "Conta criada com sucesso!"){
            Debug.Log("Log == Conta criada com sucesso");
            LP.LoginString.text = RP.UserString.text;
            LP.PassString.text = RP.PassString.text;
            RP.UserString.text = "";
            RP.EmailString.text = "";
            RP.PassString.text = "";
            LoginMode = lMode.login;
        }
    }
}
void RegisterMode(){
    LoginMode = lMode.register;
}
void LoginMod(){
    LoginMode = lMode.login;
}
}

0 个答案:

没有答案