C# ~ Networking working within Unity but not IOS

Currently i’m trying to learn how to network and play around within Unity. I created a simple runner type game that has a server side leaderboard connected to SQL database. When i clicked the submit button it works within the unity player and posts to the SQL database. But when i try to run it on IOS it gives me errors. I have tried spending time to look around the web to find the answer but i’m stumped. I’m hoping someone could help me look at this code?

public class submitScore:MonoBehaviour{

public GameplayController gpc;
string PostScoreURL = “”;

public void Button_Click()
{
EnterScore(GameObject.Find(“InputField”).GetComponent().text, gpc.score);
gpc.PlayerDiedEndTheGame();
}

public void EnterScore(stringusername,intscore)
{
WWWForm form = new WWWForm ();
form.AddField (“usernamePOST”,username);
form.AddField (“scorePOST”,score);

WWW www = new WWW(PostScoreURL, form);

//This works inside IOS?
//UnityWebRequest www = UnityWebRequest.Post(PostScoreURL,form);
}

public void GetName(){

GameObject inputFieldGo = GameObject.Find(“InputField”);
InputField inputFieldCo = inputFieldGo.GetComponent ();
Debug.Log (inputFieldCo.text);
}

}

Hello,

What’s the error you get when it run on IOS ?

1 Like

normally WWW would run in IEnumerator, and have the wait there for it to finish:
yield return www;

1 Like

Fabian-Haquin - Sorry i should have included that, there isn’t really an error per-say, i get a warning about WWW being replaced? That is why i was trying UnityWebRequests but that wasn’t working inside Unity or IOS when i tried it.

Mgear - thanks for the help, i’ll take a look a the link!

I was getting this error:

2017-01-17 07:12:37.221120 ProductName[1582:491879] You are using download over http. Currently unity adds NSAllowsArbitraryLoads to Info.plist to simplify transition, but it will be removed soon. Please consider updating to https.

But actually when Mgear placed that link it got me thinnking (i was missing the http://) which it says in that page IOS supports but i was actually missing this. Instead i just had www.<insert web page>, when i inserted http:// it worked!

Sorry i feel like such a newb, I just started Unity programming about 2 months ago (previously using snap on kind of coding engine). Really loving Unity, just need to figure out the coding. Thanks!

Don’t worry!

Anyway, WWW will indeed be replaced by UnityWebRequests but I never used it.

I was trying to do that, i noticed that it doesn’t really work though. Have you tried using it to replace that issue?

UnityWebRequest www = UnityWebRequest.Post(PostScoreURL,form);

The above code doesn’t work even when i made sure at the top to include the networking part. :eyes: