C#统一WebClient请求不适用于Android构建?

时间:2019-01-09 13:19:34

标签: c# unity3d webclient

WebClient类在编辑器和Android构建中给出不同的结果。

    void Start () {
        path = Application.persistentDataPath;
#if UNITY_EDITOR
        path = "D:/data";
#endif

        client.DownloadProgressChanged += Progress;
        client.DownloadFileCompleted += Completed;
        client.DownloadFileAsync (new Uri(url), path+"/version");
    }

    public void Progress(object sender, DownloadProgressChangedEventArgs e)
    {
        Debug.Log(e.ProgressPercentage);
    }

    public void Completed(object sender, AsyncCompletedEventArgs e)
    {
        if (e.Error != null || e.Cancelled) {
            Debug.Log(e.Error.Message);
        } 
        else
        {
            Debug.Log("Successfully Completed");
        }
    }

从Unity Editor运行时,文件下载正常。但是在为Android构建时,它会显示错误消息,例如名称解析失败

在Unity Editor上运行时,如果没有Internet连接,则会出现相同的错误。但是无论设备是否已连接到互联网,我都会在Android中收到错误消息。

0 个答案:

没有答案