I'm trying to save arbitrary files from my application's sandbox to iCloud Drive, on the iOS 10.3 simulator.
iCloud Drive is enabled and I'm signed in. If I open the iCloud Drive app on the simulator, I see files in there.
So, in my app:
I obtain the container with:
[[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil]
Which gives me something like this:
file:///Users/me/Library/Developer/CoreSimulator/Devices/F873A728-0314-4666-A137-830FF6280F05/data/Library/Mobile%20Documents/iCloud~com~me~iclouduploadtest/
Then I make my sandboxed file ubiquitous, like this:
NSError *error;
if (![[NSFileManager defaultManager] setUbiquitous:YES itemAtURL:url destinationURL:ubiquityURL error:&error])
{
NSLog(#"Error occurred: %#", error);
}
No error is reported, and if I look on disk I see the file disappear from url and appear inside the ubiquity container (the path obtained earlier).
Great! So my file is in iCloud! Or... not.
File is not visible in icloud.com, nor in iCloud Drive app on the simulator
NSMetadataQuery run on the simulator does not find the file in iCloud
Even after using Trigger iCloud sync in simulator debug menu
I try brctl log --wait --shorten and trigger the sync again. No errors are reported. Lots of starting sync down but nothing about syncing up, for any application.
Why isn't my file being uploaded to iCloud?
Am I doing something wrong, or missing a step?
Does iCloud Drive upload not work on the 10.3 simulator?
Sigh I uninstalled the app, disabled and re-enabled iCloud Drive, incremented the version and build numbers, and reinstalled the app. Now it works.
Related
From Apple's iOS development document:
https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html
So in native IOS environment, when I used Mail to open some file attachment and chose my iOS app to open it, I can find the file copied to "Documents/Inbox" directory.
But when I run iOS in Apple Silicon - the same above scenario, the file is NOT copied to "Documents/Inbox". In fact, there is no "Inbox" sub-directory under "Documents".
Does anyone know where the file copied to?
Got answer from Apple Developer Forum:
"From your app delegate's [application:openURL:options:] method, you can NSLog the [url path]."
Getting the original file path from [url path] and then copy to "Documents" which now I can manipulate this mail attachment file. So have to do this and cannot hard code the file path: "Documents/InBox" which only work reliably in iOS device..
In my flutter iOS app, every time the app is launched, it would call PathProvider.getApplicationDocumentsDirectory() to get the app documents directory to access to the previously saved data. If I install the app on an iOS device(not update here), the app could work exactly as expected. But if I updated the app from Apple Store or from Xcode, the app cannot longer be launched successfully. When I try to debug, I found the app caught exceptions at working with the drectory returned by PathProvider.getApplicationDocumentsDirectory(). Anybody could give some suggestions for fixing this? Thanks in advance.
For more information, when launched, my app has to execute createSync(recursive=true) if it does not find some app documents directories where I would store user-generated data. The app documents directories are returned by PathProvider.getApplicationDocumentsDirectory. However, after I updated the app, and when launched the app, PathProvider.getApplicationDocumentsDirectory() could still return a directory which has appropriate pattern, but the returned directory may not be the right directory since my app failed to find previously created folders there, so the app had to create the relevant directory for storing user-generated data again, and then I always got the error as below
FileSystemException: Creation failed (OS Error: Operation not permitted, errno = 1)
when I tried to create the directory with createSync(recursive=true), and no matter the version of path_provider was 1.20 or 1.10, the phenomenon persisted. Please help.
I assume the error you got is both happened in iOS simulator & iOS device ?
Get the path
Would you mind try to run on iOS simulator, and print out the path of the folder you try to access.
Open the folder in Finder
And with the printed folder path, you can open the folder with Finder by Cmd + G.
The error
Your mentioned error usually is because accessing the folder not belong to the app.
Let's see more after you print out the folder path.
I am struggling with this issue.
My app need to create, while in background, some file. It creates a temporary file (in the temporary folder), then creates a folder inside /Documents, with some files in it.
When my application is compiled in debug, it works. When I compile it in release, and only when passcode is activated, only the first set of files gets created. The second set sees only the creation of the folder inside Documents, but no file can be created, nor in temporary folder nor in Documents/newcreatedfolder.
This happens only when the application is compiled in release, and with the pass code on.
I guess it has to do with data protection and the impossibility to create new files while the phone is locked. Is there some entitlement that can give my application the possibility to create and write to new files while in background and locked?
Files are locked by standard iOS file protection policy, so after the phone is locked all files are encrypted. My solution was this, since I don't need security on those files:
[[NSFileManager defaultManager] setAttributes:#{NSFileProtectionKey:NSFileProtectionNone} ofItemAtPath:[GlobalProvider tmpFolder] error:NULL];
[[NSFileManager defaultManager] setAttributes:#{NSFileProtectionKey:NSFileProtectionNone} ofItemAtPath:[GlobalProvider documentsFolder] error:NULL];
I have created a database (IOS 5.1) with XCode 4.3.3 for the iPad and have set it up so that the user can backup and restore the database file (*.sqlite) to DropBox. Everything works fine...
Now I would like to do the same process but, set it up for iCloud. Looking for the following function:
Tap a button to backup the *.sqlite file from the Apps Document Directory up to iCloud at users preference.
Tap a button to copy the *.sqlite file down from iCloud to the Apps Document Directory.
I have been struggling trying to find the solution, any help will be greatly appreciated.
For moving any file to and from icloud you can use this code below.
[[[NSFileManager alloc]init] setUbiquitous:YES itemAtURL:your iCloudURL destinationURL:localDirectoryURL error:&errorsss];
only thing is if you are moving to icloud the code should be :
[[[NSFileManager alloc]init] setUbiquitous:YES itemAtURL:localDirectoryURL destinationURL:your_iCloudURL error:&errorsss];
and if you are getting it from iCloud to Apps Documents directory
[[[NSFileManager alloc]init] setUbiquitous:NO itemAtURL:your_iCloudURL destinationURL:localDirectoryURL error:&errorsss];
I'm using iOS 5.1
I use this peace of code
[pathURL setResourceValue:[NSNumber numberWithBool:YES]
forKey:NSURLIsExcludedFromBackupKey
error:nil];
The folder where I put my content is (inside app sandbox) .../Library/Application Support/, not a /Documents folder
I do not receive any errors and the result of setResourceValue: is YES
Why do I see 2 MB is Settings -> iCloud -> ... etc. where I can check the apps data size?
Finally I found the solution by myself
The clue is to apply NSURLIsExcludedFromBackupKey to root folder not to every file you want to exclude from backup
so at very beginning you should call this with (for example) "Library/Application Support" folder
It's worth to note that you can't just set the flag on NSHomeDirectory(). It has to be internal to that path.