UnityWebRequest在iOS中不起作用 [英] UnityWebRequest not working in iOS

查看:198
本文介绍了UnityWebRequest在iOS中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

https://docs.unity3d.com/Manual/UnityWebRequest.html 可以在Windows桌面,Windows Mobile,Android以及iOS编辑器中正常运行.但是,当我将应用程序发布到Apple App Store时,它无法连接到互联网.与其他平台不同,它没有明显的延迟,并且在尝试请求时似乎立即失败.

The examples given on https://docs.unity3d.com/Manual/UnityWebRequest.html works on Windows Desktop, Windows Mobile, Android and even in the iOS editor as expected. But when I publish the app to the Apple App Store it fails to connect to the internet. Unlike the other platforms, there is no noticeable delay and it seems to fail immediately when a request is attempted.

错误是:

未知错误

我是否需要配置XCode项目以允许iOS应用连接到互联网的任何特殊方式?

Is there any special way that I need to configure the XCode project to allow an iOS app to connect to the internet?

对于它的价值,这是进行调用的源代码:

For what it is worth, here is the source code that makes the call:

    IEnumerator SyncRequest(string data, Action<string> responseHandler)
{
    Debug.Log("Requesting " + data);

    UnityWebRequest www = UnityWebRequest.Get(baseurl + "/api-voteoptions.php?" + data);

    yield return www.Send();

    if (www.isError) // <-- Always true on published iOS app
    {
        string error = www.error; // <-- "Unknown Error"
        Debug.LogWarning(error);

        if (responseHandler != null)
        {
            responseHandler(error);
        }
    }
    else
    {
        string response = www.downloadHandler.text;
        Debug.Log(response);

        if (responseHandler != null)
        {
            responseHandler(response);
        }
    }
}

推荐答案

找到了解决方案.事实证明,我必须在Info.plist文件中指定要允许iOS应用不安全"的http连接.

Found a solution. It turns out I had to specify in the Info.plist file that I want to allow "insecure" http connections for the iOS app.

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    <key>NSExceptionDomains</key>
    <dict>
        <key>just-an-example.com</key>
        <string></string>
    </dict>
</dict>

这篇关于UnityWebRequest在iOS中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆