I am able to make the https get callout with no issues on android and the unity editor but it doesnt work on ios. Note that the url is using HTTPS, not HTTP. When trying while connected to xcode, i get the following error.
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.
NSURLConnection finished with error - code -1002
From what I have read, it seems like the plist needs edited to allow this connection but I am not sure how to do that. My plist edit code currently looks like:
[PostProcessBuild]
static void OnPostprocessBuild(BuildTarget buildTarget, string path)
{
// Read plist
var plistPath = Path.Combine(path, "Info.plist");
var plist = new PlistDocument();
plist.ReadFromFile(plistPath);
// Update value
PlistElementDict rootDict = plist.root;
rootDict.SetString("NSPhotoLibraryAddUsageDescription", "Used for saving high score screenshots");
rootDict.SetBoolean("NSIncludesSubdomains", true);
rootDict.SetBoolean("NSTemporaryExceptionAllowsInsecureHTTPLoads", true);
rootDict.SetString("NSTemporaryExceptionMinimumTLSVersion", "TLSv1.1");
// Write plist
File.WriteAllText(plistPath, plist.WriteToString());
}
The top answer on How can I add NSAppTransportSecurity to my info.plist file? gives a solution for editing the plist but im not sure if I am doing it correctly through unity. I also tried to manually edit the plist in xcode and it still didnt work. I am also not sure that this is even the issue so any other suggestions would be appreciated.
EDIT: Using xcode version 9.4 and Unity version 2018.1.2f1 personal. the code for the callout (one of them) is below:
IEnumerator getHighscores() {
loadingObject.SetActive(true);
string username = GameManager.loggedInUser;
using (UnityWebRequest request = UnityWebRequest.Get(Constants.uriBase + "/scores?username=" + username + "&apiKey=" + Constants.apiKey)) {
yield return request.SendWebRequest();
loadingObject.SetActive(false);
if (request.isNetworkError) {
ErrorMessage.text = "Unable to connect"; //THIS IS THE OUTCOME OF THE IOS CALLOUT
ErrorMessage.enabled = true;
} else if( request.isHttpError) {
if(request.responseCode == 406) {
string modifiedResponse = request.downloadHandler.text.Replace("\"", "");
ErrorMessage.text = modifiedResponse;
ErrorMessage.enabled = true;
} else {
ErrorMessage.text = "Unknown Error";
ErrorMessage.enabled = true;
}
} else {
ErrorMessage.enabled = false;
string jsonResponse = request.downloadHandler.text;
//process successful response here
}
}
}
I got it figured out. The issue was the url contained a % sign and ios apparently cant handle that.