For what it's worth.
On Thursday I finished revisions on an app I’m building. On Friday I downloaded the container for storage and backup. Then I upgraded my Mac, iPad, and xCode to support the latest versions of each. I made a few adjustments to the container and did the Replace Container process. Which has always worked before. OOPs.
I currently have:
MacOS Sonoma: 14.2.1
xCode: 15.2 (15C500b)
iPadOS: 17.3
My Development App is a sketch based app where each new sketch is stored to the database as a folder location in the documents folder Documents/pm_data/sketchName/ (sketchName like “dpc_ch1_pg1L” with L for landscape orientation). Inside the sketchName folder may be series of various images (representing sketch layers) plus a pList that describes the sketch construction. The Development App currently has 107 sketch page folders in the Documents/pm_data/ directory.
This is the process I used…to discover the error…
Download Container:
• Saves the container including AppData/Documents with the sqlite3 database showing permissions of 777. Currently the container has 107 sketch pages. This is used for back storage and retrieval. I made a couple of adjustments to this container.
Replace Container:
• Reinstalls everything from the previously downloaded container, including AppData/Documents/pm_data with 107 sketch pages. plus the sqlite3 database.
• However, no connection to the reinstalled database works.
• If I download this reinstalled container, the sqlite3 database still shows permissions of 777, and all the sketch data folder as well.
Development App Vanilla Install via Run in xCode
• Create a new sketch view
• Make a simple sketch
• Save sketch location to sqlite3 works
• Reopen sketch from the table cell in the app’s “open document” window works great
Questions:
• Why does the vanilla database which is copied from the app bundle (on first install) to the Documents folder work?
• Why does the Replace Container database in the Documents folder not work?
This is the function my code uses to copy the database from the bundle to Documents. Notice all the print() lines which are turned on for debugging.
/*
This function is in PM_DB.swift and called from AppDelegate.swift PM_DB.sharedInstance().databaseURL()
*/
func databaseURL() {
let fileManager = FileManager.default
let urls = fileManager.urls(for: .documentDirectory, in: .userDomainMask)
// If array of paths is empty, the document folder was not found.
guard urls.count != 0 else {
print("Can't find document url.")
return
}
let finalDatabaseURL:URL = urls.first!.appendingPathComponent("mats.sqlite3")
print(finalDatabaseURL)
do {
// Check if the db already exists in directory.
_ = try finalDatabaseURL.checkResourceIsReachable()
print("The db mats.sqlite3 exists in the document directory.")
} catch {
if let bundleURL = Bundle.main.url(forResource: "mats", withExtension: "sqlite3") {
print("The db mats.sqlite3 exists in the bundle directory.")
do {
try fileManager.copyItem(at: bundleURL, to: finalDatabaseURL)
print("The db mats.sqlite3 was copied to the document directory.")
} catch _ as NSError { // Handle the error
print("DB copy failed! Error:\(error.localizedDescription)")
}
} else {
print("The db does not exist in bundle folder")
}
}
}
My analysis:
Delete App and doing a Vanilla Install, xCode gives this log display:
file:///var/mobile/Containers/Data/Application/9DB4C836-B335-46B6-94C1-DEB5AFD1C3F2/Documents/mats.sqlite3
The db mats.sqlite3 exists in the bundle directory.
The db mats.sqlite3 was copied to the document directory.
WebContent process (0x113018680) took 1.463351 seconds to launch
Then I closed the running Vanilla App after the database is copied to the document directory > and in xCode Start Active Scheme to run the app, this gives an xCode log display:
file:///var/mobile/Containers/Data/Application/B33A2183-61AB-4F84-870B-19B7F1036B07/Documents/mats.sqlite3
The db mats.sqlite3 exists in the document directory.
WebContent process (0x110018680) took 1.450069 seconds to launch
In this case, I am able to create a new sketch, save it and reopen it. The newly installed database in the document directory works!
Then I stop running Vanilla App above > and Replace Container with original Download Container> and in xCode Start Active Scheme gives this xCode log display:
file:///var/mobile/Containers/Data/Application/3F07E227-81EA-4C0D-BE7E-A694A0B159A7/Documents/mats.sqlite3
The db mats.sqlite3 exists in the bundle directory.
DB copy failed! Error:The file “mats.sqlite3” couldn’t be opened because you don’t have permission to view it.
Could not create a sandbox extension for temporary file '/private/var/mobile/Containers/Data/Application/3F07E227-81EA-4C0D-BE7E-A694A0B159A7/tmp/'
Failed to get cache main folder: path for application cache was not found (errno = 13, count = 1, len = 99, path = /private/var/mobile/Containers/Data/Application/3F07E227-81EA-4C0D-BE7E-A694A0B159A7/Library/Caches)
WebContent process (0x113018680) took 1.340805 seconds to launch
So question: Why is iPadOS: 17.3 not recognizing the Replace Container mats.sqlite3. It should print("The db mats.sqlite3 exists in the document directory.") and skip the rest of the function.
Apple your system is failing on this: // Check if the db already exists in directory. compared to when working as it should in number 2 above.
So, to double check, I downloaded this latest Replacement Container and the database checks out using the terminal; all the info is there; so, the Replacement Container gets loaded correctly. My debug code confirms Apple isn’t seeing the Replaced database. In my case, the database is simple, only one table. As a workaround I’m thinking of stripping the database out of the Downloaded Container, using Replace Container to add it back to the app, and then rebuilding the copied database from the Bundle, one time in code, to repair access to the current 107 sketch pages. This is a kludge at best, and should work as long as the sketch data isn’t hosed as well.
Post
Replies
Boosts
Views
Activity
For what it's worth continued.
As a workaround I’m thinking of stripping the database out of the Downloaded Container, using Replace Container to add it back to the app, and then rebuilding the copied database from the Bundle, one time in code, to repair access to the current 107 sketch pages. This is a kludge at best, and should work as long as the sketch data isn’t hosed as well.
This did not work. Here is the result:
file:///var/mobile/Containers/Data/Application/13A2480E-8E0F-4D7B-A95A-25AD8C5BD16D/Documents/mats.sqlite3
The db mats.sqlite3 exists in the bundle directory.
DB copy failed! Error:The file “mats.sqlite3” couldn’t be opened because you don’t have permission to view it.
Could not create a sandbox extension for temporary file '/private/var/mobile/Containers/Data/Application/13A2480E-8E0F-4D7B-A95A-25AD8C5BD16D/tmp/'
Failed to get cache main folder: path for application cache was not found (errno = 13, count = 1, len = 99, path = /private/var/mobile/Containers/Data/Application/13A2480E-8E0F-4D7B-A95A-25AD8C5BD16D/Library/Caches)
WebContent process (0x10f018680) took 1.509142 seconds to launch
So, The Replace Container was stripped of the database before replacement. Then added back to the iPad app. And the bundle database can be seen existing, but now cannot be copied to the documents directory.
I need the pieces-parts and database in the documents folder because I may need to edit and save things during development. Using Replacement Container is off the list of recovery options for me until it can be fixed by Apple. I have another idea using only the bundle, but it will take a bit more time to test. At least I now have working code to rebuild the database.