Log in or register to post comments

Accessing images on iOs with Unity Web Request - Connection Error

September 14, 2022 - 1:53am #1

Hi guys,

I'm implementing an AR application where I need to load images saved on my persistentDataPath: on accessing such images through the Unity Web Request methods (I upgraded the deprecated WWW class) , a connection error is spawn. I attached the logs files from XCode in a zip folder. Here is part of my code (I  think it could be related to the URL where the images are located and how iOs converts/read it)

public IEnumerator CreateGuideViewButton()

    {

        Buttons = new List<Button>();

        mContent = GameObject.FindGameObjectWithTag("Content");

        string mPath = Application.persistentDataPath + "/BH Inspection Plan/Vuforia Dataset/" + FileExplorer.mFileName + "/dataset";

        mInfo = new DirectoryInfo(mPath);

        mFiles = mInfo.GetFiles("*_1.png");

        Debug.Log(mPath);

        int mPNGs = mFiles.Length;

        for (int i = 0; i < mPNGs; i++)

        {

            string mName = i.ToString();

            Button mPrefabButton = Resources.Load<Button>("MyButton") as Button; 

            Button mMyButton = Instantiate(mPrefabButton);

            mMyButton.name = mName;

            mMyButton.transform.SetParent(mContent.transform);

            if (i % 2 == 0) 

            {

                

                mMyButton.GetComponent<RectTransform>().localPosition = new Vector3(mXEven, mYEven, 0);

                mMyButton.GetComponent<RectTransform>().sizeDelta = new Vector2(side, side);

                mYEven -= 450;

               

                string mImagePath = Path.Combine(mPath, (FileExplorer.mFileName + "_viewpoint_000" + i + "_1.png"))

               

                UnityWebRequest www =  UnityWebRequestTexture.GetTexture(mImagePath);

                yield return www.SendWebRequest();

               

                if (www.result == UnityWebRequest.Result.InProgress)

                {

                    continue;

                }

                else if (www.result == UnityWebRequest.Result.ConnectionError)

                {

                    Debug.Log(www.error);

                    yield return false;

                }

                else if (www.result == UnityWebRequest.Result.Success)

                {

                    texture = DownloadHandlerTexture.GetContent(www);

                }

              

                int width = texture.width;   

                int height = texture.height; 

               if (height >= width) 

                {

                    RawImage mPrefabImageHeight = Resources.Load<RawImage>("MyImageHeight") as RawImage;

                    RawImage mMyImage = Instantiate(mPrefabImageHeight);

                    mMyImage.gameObject.transform.SetParent(mMyButton.transform);

                    mMyImage.GetComponent<RectTransform>().localPosition = Vector3.zero;

                    mMyImage.GetComponent<RawImage>().texture = texture; 

                }

                else

                {

                    RawImage mPrefabImageWidth = Resources.Load<RawImage>("MyImageWidth") as RawImage;

                    RawImage mMyImage = Instantiate(mPrefabImageWidth);

                    mMyImage.gameObject.transform.SetParent(mMyButton.transform);

                    mMyImage.GetComponent<RectTransform>().localPosition = Vector3.zero;

                    mMyImage.GetComponent<RawImage>().texture = texture; 

                }

            }

 

Thanks in advance!

AttachmentSize
Package icon Logs.zip471.62 KB
Log in or register to post comments