Prevent app from backing up files in the documents folder? - swift

I am not able the test my case, because I simply don't know when the synchronisation process of syncing files is triggered. Thats why I am asking this here.
I have a lot of files and subfolders in my apps document folder and want to prevent from backup up these files in ICloud (which seems to be stupidly the default).
Is it necessary to mark all these files with
MyFile.setResourceValue(NSNumber.numberWithBool(true), forKey: NSURLIsExcludedFromBackupKey, error: &err)
or is it good enough to only mark the root document folder once and all childs will also be marked with ExcludedFromBackup implicitely ?

u can use it for root directory only
Starting in iOS 5.1, apps can use either
NSURLIsExcludedFromBackupKey or kCFURLIsExcludedFromBackupKey file
system properties to exclude files and directories from backups.
In details look Technical Q&A QA1719

Related

Deleting an iOS App with documents in the iCloud-enabled folder

I found out that if I delete an App from the device, all local documents are deleted of course, but if the App has files stored in the iCloud-enabled folder ([[[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil]) - These files are not deleted.
This causes two problems:
The storage taken by these files is not freed.
If the user re-installs the App, there are already files in the folder, which disrupts normal initialization.
I can take care of the second issue by going through the directory on first launch and deleting everything in there, but it seems a bit awkward.
I can't think of a way to take care of the first issue.
Any ideas?
iOS automatically purges files in the iCloud directory to free up space. You may also specifically "evict" files from your app, but since you are addressing the scenario in which the app is deleted, that probably won't be much help.
See the videos at developer.apple.com/icloud for more info.

iPhone project - collect files into one place

Sorry if this has been answered before but all my searches do not return anything related to this.
Is there a way to collect all the files referenced in a project and save them in the procject folder automatically? Rather that having links to places where you may accidentally delete the files.
Thanks,
Eds
Xcode doesn't have a particular feature to support this, but when you add items to your Xcode project it does give you the option to copy those items to the project directory. Otherwise you need to manually copy the items to a common location.
What do you mean collect all the files? Do you mean your external files or class files. Your external files like images or audio/video files should be added into Resources directory, it does not matter where is the root directory of these files. Then, you can access with their name in the project.

file sharing on iphone/ipad?

I want my app to share files via itunes file sharing. Right now all of the Documents folder
is exposed to the user. The problem is that there are certain files there (let's say these are "System files") that I don't want to expose. What should I do? And if it's not possible to "hide" files, where do you think it's best to put "System files"? In the Library folder?
Thanks
Apple has a Technical Q&A dealing with exactly this.
In addition to the directories
documented previously, the entire
/Library directory
has always been preserved during
updates and backups, except for
/Library/Caches.
Because of this, applications can
create their own directories in
/Library/ and those
directories will be preserved in
backups and across updates. To
minimize the risk of name collisions,
we recommend that you name this
directory carefully. For example, a
directory named Private Documents
would be a good choice.
Yes, the Library folder is a good choice. The Documents folder should be reserved for the user's documents. Alternatively, you can prefix the filenames of your "system files" with a . or put them in a .hidden subfolder of the Documents folder. Those hidden files are currently not shown in iTunes AFAIK.

iPhone Documents directory and UIFileSharingEnabled, hiding certain documents

I want the user to be able to access the files in the documents directory but am using core data and dont want the user to be able to access the store (the sqllite db), can i hide it from the user while still allowing file sharing, or can i put it in another directory where it will still get backed up?
The answer given by FrenchKiss Dev is not correct. The user will still be able to see the ".data" directory in iTunes and save that locally with all the files inside it.
Instead, store private documents in Library/Preferences
According to Apple:
In addition to the directories documented previously, the entire
/Library directory has always been preserved during
updates and backups, except for /Library/Caches.
Because of this, applications can create their own directories in
/Library/ and those directories will be preserved in
backups and across updates. To minimize the risk of name collisions,
we recommend that you name this directory carefully. For example, a
directory named Private Documents would be a good choice. You should
store any files you don't want to share to Library/Preferences.
In the documents directory, create a subdirectory which name starts with a dot. For example:
.data
EDIT: Please stop downgrading this answer !
This answer was correct at the time (remember that it was before the iPad was actually available! And there was a lot of confusion on the matter, we were still hoping for the iPad to appear in the shared devices in the Finder...).
Today (April 2012) it is still working on the Mac but not on Windows (starting a directory name with a dot means nothing in Windows).
Anyway, this Shared Document feature is a mess. Later they fixed it by saying that "Private Documents" should be stored in the Library Folder not in the Documents folder. But remember that developers were already using the Document folder before the iPad came.
Don't blame me for Apple mistakes.
Stack Overflow should have a way to mark an answer as obsolete.
API changes, get fixed, and it renders answers obsolete.

iPhone SDK - Adding zipped content in resources and then unzipping into Documents folder

I have some resources (zipped) that needs to be shipped with my iphone application. When the app launches for the first time, this zipped file needs to be moved/copied to the Documents folder and unzip it there. User can then add more files to this path from the application. Can someone please suggest how can I achieve this?
Thanks!
Based on your comment above:
The reason I want to add a compressed
resource because there are multiple
files. If I don't compress then I'll
need to move files individually. I'll
also need to maintain a list of files
somewhere so that I can read the file
name and then move them. I thought
zipping and unzipping was a simpler
solution.
You could add all the files to a folder in your bundle. When the app launches for the first time use fast enumeration to run through the folder and what ever it finds in that folder, it copies into the Documents folder. Handling folders within folders is slightly more complex (add recursion maybe). This way you don't have to worry about zip or tar, nor to keep a directory of files to install.
Just place the folder of files you want into Xcode's resources folder and tell it to import as a folder not as a group. That way the files get installed in your resources inside a folder instead of just as individual files all over the place.
EDIT:
Better yet, do what I say about putting all the files you want in one folder, add to your project, but not as a "Group", and then at first launch use:
[[NSFileManager defaultManager] copyItemAtPath:(NSString *)srcPath toPath:(NSString *)dstPath error:(NSError **)error];
and it will copy your whole directory from one place to another. EASY!
Add the libz.dylib Framework to your project, and include Deusty's NSData gzip category which will give you compression/decompression methods.
While this is available by using the libz.dylib, it really is unnecessary as it save you little (if any) space. You application bundle is already compressed when being transferred to the phone. Compression on top of compression usually yields little additional compression.
Try it out yourself. You may find that shipping your app with unzipped contents may take up just as much space as zipped contents.