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?
Solved! Go to Solution.
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?
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?
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