- Home /
Download then open image on IOS
This code works perfectly on Android, but won`t do anything on IOS:
public class OnPressingPictureButton : MonoBehaviour {
public int currentPage;
public string [] imageURL;
public Book book;
public GameObject loading;
// Update is called once per frame
void Update () {
currentPage = book.page;
}
void OnMouseDown ()
{
loading.SetActive (true); //@@@ "Loading ON"
//Checking if the file exists in the users device
if (System.IO.File.Exists (Application.persistentDataPath + "/image" + currentPage.ToString() + ".jpg")) {
//if yes, open it
loading.SetActive (false);
Application.OpenURL (Application.persistentDataPath + "/image" + currentPage.ToString() + ".jpg");
}
//if not, download it
else {
StartCoroutine (TestDownload (imageURL [currentPage]));
}
}
private IEnumerator TestDownload (string uRL)
{
WWW www = new WWW (uRL);
yield return www;
while (!www.isDone) {
Debug.Log (www.progress);
yield return null;
}
string savePath = Application.persistentDataPath + "/image" + currentPage.ToString() + ".jpg";
byte[] bytes = www.bytes;
System.IO.File.WriteAllBytes (savePath, bytes);
loading.SetActive (false); //@@@ "Loading OFF"
Application.OpenURL (savePath);
}
}
I tried changing from "File.Exists" to "Directory.Exists" and also added "file://" on the beginning of savePath variable, but it still does not seem to work.
any ideas?
Comment