En este momento estás viendo Unity – IOS persistDataPath acceso denegado // No se pudo abrir la base de datos

 – Unity

Unity – IOS persistDataPath acceso denegado // No se pudo abrir la base de datos – Unity

Unity – IOS persistDataPath acceso denegado // No se pudo abrir la base de datos

– UnityAssets3Free

hola , me llamo Daniel y para hoy os traigo
esta unity pregunta

Estoy tratando de recuperar un archivo de mis activos de transmisión y hacer una copia en el archivo persistDataPath.

El problema es que iOS niega el acceso a persistDataPath, por lo que no puedo escribir el archivo, ¿alguien puede decirme por qué?

Código:

#elif UNITY_IOS
if (File.Exists(Application.dataPath + "/Raw/" + StaticDatas.databaseName))
 SQLiteOpenFlags.Create);
        CreateDB();

Error: se denegó el acceso a la ruta /var/mobile/containers/dta/application/manythings/DocumentsDatabaseName.db «

IOS: 9.5.3 Unidad: 5.5.0f3

————————————————– ————–

ACTUALIZACIÓN: StaticDatas.databasePath = persistDataPath

————————————————– ————–

ACTUALIZACIÓN 2:

Bueno, estoy completamente perdido…

Aquí está el código que tengo:

#elif UNITY_IOS

string basePath = Path.Combine(Application.dataPath + "Raw" , StaticDatas.databaseName);
string targetPath = Path.Combine(StaticDatas.databasePath , StaticDatas.databaseName );
Debug.Log(basePath);
Debug.Log(targetPath);
if (File.Exists(basePath))

    byte[] bytes = null;

        Debug.Log("base path exists");
           using (FileStream fileStream = File.OpenRead(basePath))
           
               Debug.Log("create byte array");
               bytes = new byte[fileStream.Length];
               Debug.Log(" READ BYTES");
               fileStream.Read(bytes,0,int.Parse(fileStream.Length+""));
               Debug.Log(" CLOSE");
               fileStream.Close();
               Debug.Log("DISPOSE");
               fileStream.Dispose();
           
           Debug.Log(" Check if dir exists");
          /* if (!Directory.Exists(StaticDatas.databasePath + "/AnnotationTest.app/database/"))
           
                Debug.Log(" create folder");
                Directory.CreateDirectory(StaticDatas.databasePath + "/AnnotationTest.app/database/");
           */
           Debug.Log("Open file");
           FileStream fs = File.Open(targetPath, FileMode.OpenOrCreate);
         Debug.Log("Write file");
           fs.Write(bytes, 0, bytes.Length);
           Debug.Log(" CLOSE STRREAM");
           fs.Close();
       Debug.Log("Connec close");
         _connection = new SQLiteConnection(targetPath, SQLiteOpenFlags.ReadWrite 



if (File.Exists("file:" + Application.dataPath + "/Raw/" + StaticDatas.databaseName));

    Debug.Log("file datapath raw databasename");
          byte[] bytes = null;

        Debug.Log("base path exists");
           using (FileStream fileStream = File.OpenRead("file:" + Application.dataPath + "/Raw/" + StaticDatas.databaseName))
           
               Debug.Log("create byte array");
               bytes = new byte[fileStream.Length];
               Debug.Log(" READ BYTES");
               fileStream.Read(bytes,0,int.Parse(fileStream.Length+""));
               Debug.Log(" CLOSE");
               fileStream.Close();
               Debug.Log("DISPOSE");
               fileStream.Dispose();
           
            FileStream fs = File.Open(targetPath, FileMode.OpenOrCreate);
         Debug.Log("Write file");
           fs.Write(bytes, 0, bytes.Length);
           Debug.Log(" CLOSE STRREAM");
           fs.Close();

         _connection = new SQLiteConnection(targetPath, SQLiteOpenFlags.ReadWrite 

#else
            var loadDb = StaticDatas.databasePath + StaticDatas.databaseName;
            File.Copy(loadDb, filePath);
         _connection = new SQLiteConnection(filePath, SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create);
        CreateDB();
#endif

La primera declaración if funcionó por un momento (sin combine), pero ahora, maní.

El segundo devuelve verdadero (Exists), pero cuando llega a la declaración de uso, dice «No se pudo encontrar una parte de la ruta» (¿incluso si la encuentra en la declaración if, wtf?)

————————————————– ————–

ACTUALIZAR 3

¡Es un milagro! ¡Yo encontré! Bueno, ahora SQLite no pudo abrir la base de datos, ¡pero la encontré!

string bpa = Application.dataPath + "/Raw/" + StaticDatas.databaseName;

if (File.Exists(bpa))

    byte[] b = null;
    using (FileStream fs = File.OpenRead(bpa))
    
        b = new byte[fs.Length];
        fs.Read(b, 0, int.Parse(fs.Length+""));
        fs.Close();
        fs.Dispose();
    
    FileStream fsa = File.Open(targetPath, FileMode.OpenOrCreate);
    fsa.Write(b,0, b.Length);
    fsa.Close();
    _connection = new SQLiteConnection(targetPath, SQLiteOpenFlags.ReadWrite 
else if (File.Exists(basePath))
 SQLiteOpenFlags.Create);
        CreateDB();

Así que la ruta correcta parece ser:

 string bpa = Application.dataPath + "/Raw/" + StaticDatas.databaseName;

————————————————– ————–

ACTUALIZACIÓN 4:

Bien, creo que sé cuál es el problema (incluso si no lo entiendo):

Ahora puedo obtener mis datos de transmisión assets y copiarlo en persistDatapath, pero cuando creo una conexión con el archivo, SQLite genera una excepción:

Could not open database file

¿Alguien sabe por qué?

————————————————– ————–
ACTUALIZACIÓN 5:

Hago Combine para crear la ruta «targetPath», en los registros muestra «/var/mobile/Container/Data/Application/manylettersanddigits/Documents/database.db»

Sin embargo, en SQLException muestra lo mismo pero sin la barra entre Documentos y base de datos.db

1 respuesta 1

En IOS, la ruta actual para la transmisión assets se puede acceder con:

Application.dataPath + "/Raw/" + StaticDatas.databaseName;

EN ESTE CASO el «No se pudo abrir el archivo de la base de datos» fue causado porque estaba creando 2 conexiones en el método (que pena) Efectivamente la segunda estaba haciendo buggig (misma variable para ambas), fue mi error.

Gracias a todos.

nota: si aun no se resuelve tu pregunta por favor dejar un comentario y pronto lo podremos de nuevo , muchas gracias

eso es todo,espero que te funcione

Deja una respuesta