Excluding files from iCloud backup - ios

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.

Related

iOS ubiquitous file not uploaded to iCloud (simulator)

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.

file manager is not clearing from older app

Hello I have an app in my code that loads a file into a Bluetooth device, but it seems like if I change that file for the new version of the app it doesn't update it if I just reinstall it. I have to actually delete the app and install it again. Anyone know why? Is there some cache storing?
NSString *fileInDocuments = [documentsDirectory stringByAppendingPathComponent:#"samplefile_pack.bin"];
NSLog(#"File: %#", fileInDocuments);
if ([fileManager fileExistsAtPath:fileInDocuments ] == NO) {
NSString *resourcePath = [[NSBundle mainBundle] pathForResource:#"samplefile_pack" ofType:#"bin"];
[fileManager copyItemAtPath:resourcePath toPath:fileInDocuments error:&error];
}
I'm assuming v1 of your app has the same code as the v2 of your app posted in your question. Assuming this is true, the behavior you see makes perfect sense.
A user runs v1 of your app. The file isn't in the Documents folder so it gets copied from the app bundle. Now, every time they run your app, the file exists and that copy in Documents is used.
Now the user updates to v2 of your app. The same check is made. The file already exists in Documents so nothing is copied.
Since your question implies that you want an updated copy of this file installed the 1st time v2 of the app is run, you need to detect whether the user currently has the file from v1 or v2 in the Documents folder.
There are a few ways to solve this. One option is to rename the file to something like samplefile_pack2.bin. Then your check can be for the new file name. You can also check for the old one and delete it if it makes sense.

Xcode Device Simulator Files

I have been clearing some space from my drive and noticed that there are 183 folders inside my Developer>CoreSimulator>Devices folder. Are all of these required or are some of these simulators for older versions of iOS. When I look inside some of the folders they contain a file called device.plist that says the Sim Runtime is iOS-8-4. Is there any way to remove these old files?
Thanks
~/Library/Developer/CoreSimulator
Core Simulator folder is familiar for many Xcode users. It’s simulator’s territory; thats where it stores app data. It’s obvious that you can toss the older version simulator folder/folders if you no longer support your apps for those versions. And, it’s safer to use ‘Reset content and Settings’ option from menu to delete all of your app data in a Simulator.
Tip:
Objective-C
[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
Swift
NSFileManager.defaultManager().URLsForDirectory(NSDocumentDirectory, inDomains: NSUserDomainMask).lastObject()
Will print the full path to the document directory folder.

App creating files while iPhone is locked

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 can't find ios simulator files

I need to look my application's database file.I found this question:
How view data stored in Core Data?
In answer he said:
Your app will be folder inside (~ is your home directory):
~/Library/Application Support/iPhone Simulator/User/Applications/
I opened the Application Support folder but there is no iPhone Simulator folder inside this folder.
What should I do ? Here is the screenshot:
Edit:I am using xCode 6 and Yosemite.
The iPhone Simulator files have moved and can be a bit of a pain to find now. Each simulated device has a folder in ~/Library/Developer/CoreSimulator/Devices. You can root around in there until you find the simulator you're looking for. I wrote a tool to help locate the sandbox for each simulated device on which you've installed an app, but it's not perfect. You can find it here: https://github.com/somegeekintn/SimDirs
There is also an app called SimPholders2 that may be able to help you with this problem - http://simpholders.com/
for me it it is Library/Developer/CoreSimulator/Devices/C7E8D457-BFAB-43DA-8B0C-D9010BBB1D88/data/Containers/Data/Application/6B7DC6FA-2379-468C-A74B-60910A1CDCD1/Documents
device id and application id will be different for you though. this would give you documents directory for your app.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSLog (#"documentsDirectory %#",documentsDirectory);
OK The whole Problem lies in the fact that you need to open the Finder >> View >> Show View Options and then click to turn on Library.
Why would someone hide this so deep and obscurely?
You can use Core Data Lab to automatically find and view the database files of any Core Data app running in the simulator.
Info page: https://betamagic.nl/products/coredatalab.html
Free 14-trial: https://betamagic.nl/downloads/Core%20Data%20Lab%20Trial.zip
Diclaimer: I'm the creator of this tool.

Resources