AppStudio FileInfo Not Working on iOS 12

444
2
Jump to solution
03-28-2019 01:39 PM
ChristopherEby2
New Contributor III

I am testing my AppStudio 3.3 beta app on a 6th Gen iPad running iOS 12. In my code I am trying to access a file using the AppFramework.FileInfo object to verify that the file exists and then read its size. However, the code that works on Windows does not work on iOS. Here is my code:

function checkFile(filePath) {
   var fileInfo = Qt.createQmlObject('import ArcGIS.AppFramework 1.0; FileInfo { filePath: "' + filePath + '" }', app);

   console.log('File Exists?', fileInfo.exists, 'File Size?', fileInfo.size)

}

When my code runs on a file path like "var/mobile/Containers/Data/Application/F343D1DB-5FBC-488C-919A-6A6893944420/Documents/img_0050.jpg" I get the output "File Exists? false File Size? 0" in iOS. When I list the files in "var/mobile/Containers/Data/Application/F343D1DB-5FBC-488C-919A-6A6893944420/Documents" to the console using the FileFolder object I can see that img_0050.jpg is there but even the FileFolder.exists() method returns false. How can I fix this?

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ChristopherEby2
New Contributor III

It turns out that I was missing a leading slash that is necessary on iOS. Here's what I did to fix it:

function checkFile(filePath) {

   var slash = Qt.platform.os === 'ios' ? '/' : '\\';
   var fileInfo = Qt.createQmlObject('import ArcGIS.AppFramework 1.0; FileInfo { filePath: "' + slash + filePath + '" }', app);

   console.log('File Exists?', fileInfo.exists, 'File Size?', fileInfo.size)

}

Is there a cleaner way to do this?

View solution in original post

0 Kudos
2 Replies
ChristopherEby2
New Contributor III

It turns out that I was missing a leading slash that is necessary on iOS. Here's what I did to fix it:

function checkFile(filePath) {

   var slash = Qt.platform.os === 'ios' ? '/' : '\\';
   var fileInfo = Qt.createQmlObject('import ArcGIS.AppFramework 1.0; FileInfo { filePath: "' + slash + filePath + '" }', app);

   console.log('File Exists?', fileInfo.exists, 'File Size?', fileInfo.size)

}

Is there a cleaner way to do this?

0 Kudos
StephenQuan1
Esri Contributor

Hi Christopher,

There are a number of useful properties and methods on the AppFramework object, such as:

Also, while we're at it, there is a useful method on the App object itself,

function checkExists(fileName) {
    return app.folder.fileExists(fileName);

    // app.folder will be a FileFolder object for your app, e.g. /var/mobile/Containers/Data/Application/F343D1DB-5FBC-488C-919A-6A6893944420/Documents
    // then you just call fileExists('img_0050.jpg')
}
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Stephen

0 Kudos