[유니티 / iOS] iOS 파일 저장 경로 오류 : UnauthorizedAccessException: Access to the path

Posted by Dev Park
2020. 8. 12. 08:08 Unity_iOS

 

 

iOS에서 파일 저장을 할때 

UnauthorizedAccessException: Access to the path is denies

 또는 경로를 찾을 수 없다는 오류가 뜨는 경우 해결 방법입니다. 

 

이 문제는 

string path = Application.dataPath.Substring(0, Application.dataPath.Length - 5);

이렇게 코드를 쓸 경우 

UnauthorizedAccessException: Access to the path "/var/containers/Bundle/Application/9DA2D489-2037-451E-87D1-FA7354ECD0D1/Documents" is denied. 같은 오류가 발생 합니다. 

 

이때는 코드를 Application.dataPath 가 아닌 Application.persistentDataPath 를 사용하면 해결 됩니다. 

 

https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html

 

Unity - Scripting API: Application.persistentDataPath

This value is a directory path where you can store data that you want to be kept between runs. When you publish on iOS and Android, persistentDataPath points to a public directory on the device. Files in this location are not erased by app updates. The fil

docs.unity3d.com

참고한 내용 

https://stackoverrun.com/ko/q/12392639