Hi, just following your trails on this old thread. Wondering if any of the apps using “System.DocumentsDirectory” for downloaded and unzipped content got rejected by Apple. A short update (all ok or rejected by Apple etc) would be very appreciated. Thanks
I know people have been rejected for storing too much in system.DocumentsDirectory. When the added the system.CachesDirectory, they were quite clear that if it can be downloaded, it needs to go there. When they added iCloud backups, they started looking even closer at what’s being stored because iCloud storage is limited.
If you need to keep things in system.DocumentsDirectory and its more than a few kbytes in size, you probably should set the flag that tells iOS not to back it up.
Absolutely. I will use the method shared above by @shivapp and will turn off synch. I was just wondering whether @shivapp or @rxmarccall (or others) had any trouble using this approach. Thanks for your feedback.
Have a look at my copy directory to directory <code>cp</code> below, with option to turn on/off iCloud backup, which i developed for XMobile Vietnam.
Case: the zip file downloaded to Temp directory, after extract it, we copy to Document dir with option to turn off icloud backup.
– copy content of srcDir at srcBaseDir to destDir at destBaseDir
–return: true/false
– if the platform iOS, we turn off iCloudBackup
function device.cp(srcDir, srcBaseDir, destDir, destBaseDir, overwrite, icloud)
if( (srcBaseDir~= system.ResourceDirectory) and (device.cd(srcDir, srcBaseDir) == false)) then
print(“dir:” … srcDir … " not existed. stop copying")
log(“xmdevice”, “dir:” … srcDir … " not existed. stop copying")
return false
end
if( device.cd(destDir, destBaseDir) == false) then
print(“dest dir:” … destDir … " not existed. create it")
log(“xmdevice”, “dest dir:” … destDir … " not existed. create it")
device.mkdir(destDir, destBaseDir)
end
local lfs = require “lfs”
local doc_path = system.pathForFile( srcDir, srcBaseDir)
for filename in lfs.dir(doc_path) do
if( filename == “.” or filename == “…”) then
else
local src_path = system.pathForFile(srcDir … “/” … filename, srcBaseDir)
local dest_path = system.pathForFile(destDir … “/” … filename, destBaseDir)
print(“copying from:” … src_path )
print(“copying to:” … dest_path )
--log(“xmdevice”, “copying from:” … src_path )
--log(“xmdevice”, “copying to:” … dest_path )
--try to test the dest file
local destFileHandle = io.open(dest_path, “r”)
local shouldCopy = true
if( destFileHandle and overwrite) then
print(“File:” … dest_path … " existed and will be overwriten")
– log(“xmdevice”, “File:” … dest_path … " existed and will be overwriten")
shouldCopy = true
io.close(destFileHandle)
elseif( destFileHandle and (overwrite == false) )then
print(“File:” … dest_path … " existed and will NOT be overwriten")
– log(“xmdevice”, “File:” … dest_path … " existed and will NOT be overwriten")
shouldCopy = false
io.close(destFileHandle)
else
print(“File:” … dest_path … " not existed. Copy new file")
--log(“xmdevice”, “File:” … dest_path … " not existed. Copy new file")
shouldCopy = true
end
if( shouldCopy) then
local srcFileHandle = io.open(src_path, “r”)
destFileHandle = io.open(dest_path, “w”)
local fileBuff = srcFileHandle:read( “*a” )
--write to dest
destFileHandle:write( fileBuff )
--close all
io.close(srcFileHandle)
io.close(destFileHandle)
fileBuff = nil
--16/03/2015: if iOS then check for turn on/off backup
if (string.lower(device.platform) == string.lower(“iPhone OS”)) then
– log(“xmdevice”, “native.setSync(” … destDir … “/” … filename… “) to” …tostring(icloud) )
native.setSync(destDir … “/” … filename,{ iCloudBackup = icloud })
end
else
end
end
end
end
Have a look at my copy directory to directory <code>cp</code> below, with option to turn on/off iCloud backup, which i developed for XMobile Vietnam.
Case: the zip file downloaded to Temp directory, after extract it, we copy to Document dir with option to turn off icloud backup.
– copy content of srcDir at srcBaseDir to destDir at destBaseDir
–return: true/false
– if the platform iOS, we turn off iCloudBackup
function device.cp(srcDir, srcBaseDir, destDir, destBaseDir, overwrite, icloud)
if( (srcBaseDir~= system.ResourceDirectory) and (device.cd(srcDir, srcBaseDir) == false)) then
print(“dir:” … srcDir … " not existed. stop copying")
log(“xmdevice”, “dir:” … srcDir … " not existed. stop copying")
return false
end
if( device.cd(destDir, destBaseDir) == false) then
print(“dest dir:” … destDir … " not existed. create it")
log(“xmdevice”, “dest dir:” … destDir … " not existed. create it")
device.mkdir(destDir, destBaseDir)
end
local lfs = require “lfs”
local doc_path = system.pathForFile( srcDir, srcBaseDir)
for filename in lfs.dir(doc_path) do
if( filename == “.” or filename == “…”) then
else
local src_path = system.pathForFile(srcDir … “/” … filename, srcBaseDir)
local dest_path = system.pathForFile(destDir … “/” … filename, destBaseDir)
print(“copying from:” … src_path )
print(“copying to:” … dest_path )
--log(“xmdevice”, “copying from:” … src_path )
--log(“xmdevice”, “copying to:” … dest_path )
--try to test the dest file
local destFileHandle = io.open(dest_path, “r”)
local shouldCopy = true
if( destFileHandle and overwrite) then
print(“File:” … dest_path … " existed and will be overwriten")
– log(“xmdevice”, “File:” … dest_path … " existed and will be overwriten")
shouldCopy = true
io.close(destFileHandle)
elseif( destFileHandle and (overwrite == false) )then
print(“File:” … dest_path … " existed and will NOT be overwriten")
– log(“xmdevice”, “File:” … dest_path … " existed and will NOT be overwriten")
shouldCopy = false
io.close(destFileHandle)
else
print(“File:” … dest_path … " not existed. Copy new file")
--log(“xmdevice”, “File:” … dest_path … " not existed. Copy new file")
shouldCopy = true
end
if( shouldCopy) then
local srcFileHandle = io.open(src_path, “r”)
destFileHandle = io.open(dest_path, “w”)
local fileBuff = srcFileHandle:read( “*a” )
--write to dest
destFileHandle:write( fileBuff )
--close all
io.close(srcFileHandle)
io.close(destFileHandle)
fileBuff = nil
--16/03/2015: if iOS then check for turn on/off backup
if (string.lower(device.platform) == string.lower(“iPhone OS”)) then
– log(“xmdevice”, “native.setSync(” … destDir … “/” … filename… “) to” …tostring(icloud) )
native.setSync(destDir … “/” … filename,{ iCloudBackup = icloud })
end
else
end
end
end
end