This article has participated in the Denver Nuggets Creators Camp 3 “More Productive writing” track, see details: Digg project | creators Camp 3 ongoing, “write” personal impact.

Unity error: UnauthorizedAccessException

Error reason: in the iOS wrong use directly using the Application. The persistentDataPath this directory.

Wrong method of use: Application. PersistentDataPath + gameType + “_dRule. TXT”,,, the way of using the Android mobile terminal is no problem, perhaps because the Android less strict requirements for permissions.

Correct method of use: Application. The gameType persistentDataPath + “/” + + “_dRule. TXT”,,, need to add “/” as a subdirectory.

Error:

UnauthorizedAccessException: Access to the path “/var/mobile/Containers/Data/Application/E9F05959-AC99-47EB-803F-3B4CE5C6673E/DocumentsHLJ_HUN_dRule.txt” is denied. at System.IO.FileStream.. ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) [0x00000] in :0 at System.IO.FileInfo.Open (FileMode mode, FileAccess access, FileShare share) [0x00000] in :0 at System.IO.FileInfo.CreateText () [0x00000] in :0 at CreateTableCtrl.CreateRoom (GAME_KIND gameType) [0x00000] in :0 at UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction1 functor) [0x00000] in

:0 \ at UnityEngine.EventSystems.StandaloneInputModule.ProcessTouchPress (UnityEngine.EventSystems.PointerEventData pointerEvent, Boolean pressed, Boolean released) [0x00000] in

:0 \ at UnityEngine.EventSystems.StandaloneInputModule.ProcessTouchEvents () [0x00000] in

:0 \ at UnityEngine.EventSystems.StandaloneInputModule.Process () [0x00000] in

:0 \ UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction1) UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean) UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchEvents() UnityEngine.EventSystems.StandaloneInputModule:Process()\