Hello people, Im getting a error when I try to copy a file from StreamingAssets Application.dataPath
to Application.persistentDataPath
On android works fine, but on IOS im getting this error:
*App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Use HTTPS instead or add Exception Domains to your app's Info.plist.
*Cannot start load of Task <XXXXXXX>.<2> since it does not conform to ATS policy
*Task <XXXXXXX>.<2> finished with error [-1022] Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection." UserInfo={NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection., NSErrorFailingURLStringKey=http://localhost/private/var/containers/Bundle/Application/XXXXXXX/AppnName/Data/Raw/xlsx/puestaapunto.xlsx, NSErrorFailingURLKey=http://localhost/private/var/containers/Bundle/Application/XXXXXXX/AppnName/Data/Raw/xlsx/puestaapunto.xlsx, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDataTask <XXXXXXX>.<2>"
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <XXXXXXX>.<2>, NSUnderlyingError=0x280b88a80 {Error Domain=kCFErrorDomainCFNetwork Code=-1022 "(null)"}}
SOLVED
this code works for android:
#if UNITY_ANDROID
string oriPath = Path.Combine("jar:file://" + Application.dataPath + "!/assets/xlsx/", ExcelFileName + ".xlsx"); //returns a DirectoryInfo object
UnityWebRequest reader = UnityWebRequest.Get(oriPath);
reader.SendWebRequest();
while (!reader.isDone) { }
realPath = Application.persistentDataPath + "/xlsx/" + ExcelFileName + ".xlsx"; //save the file with this name
File.WriteAllBytes(realPath, reader.downloadHandler.data);
Debug.Log("Excel File generated in app data from StreamingAssets");
#endif
and this code works for iOS:
#if UNITY_IOS
realPath = Application.persistentDataPath + "/xlsx/";
string oriPath = Path.Combine(Application.streamingAssetsPath + "/xlsx", ExcelFileName + ".xlsx"); //returns a DirectoryInfo object
byte[] xlsxFile = File.ReadAllBytes(oriPath);
File.WriteAllBytes(realPath + ExcelFileName + ".xlsx", xlsxFile); //save the file with this name
//File.WriteAllBytes(realPath + "puestaapunto.xlsx", xlsxFile); //alternative of above line, working
Debug.Log("Excel File generated in app data from StreamingAssets");
#endif