iosxcodeicloudnsdocumentdirectoryicloud-drive

If I don't enable iCloud backup, will I have to exlude my document directory to prevent files from being backed up to iCloud and iTunes?


After reading this question, you would surely be thinking to mark this as duplicate. I am aware of following solution to exclude file or folder. But, do I really need to do it if my App does not support iCloud documents under Capabilities in Xcode ?

Here is the solution which is applicable for my case:

func addSkipBackupAttributeToItemAtURL(filePath:String) -> Bool
{
    let URL:NSURL = NSURL.fileURLWithPath(filePath)

    assert(NSFileManager.defaultManager().fileExistsAtPath(filePath), "File \(filePath) does not exist")

    var success: Bool

    do {
        try URL.setResourceValue(true, forKey:NSURLIsExcludedFromBackupKey)
        success = true

    } catch let error as NSError {

        success = false
        print("Error excluding \(URL.lastPathComponent) from backup \(error)");
    }

    return success
}

Is it necessary if I disable iCloud documents under Capabilities in Xcode as following:

enter image description here


Solution

  • Those are for two different purpose.

    iCloud in Xcode Capability: It's for enabling iCloud related features in your application.

    NSURLIsExcludedFromBackupKey: By default the user data is backed up to iCloud by iOS (If user opted iCloud backup). Only user data not application data.

    User Data: The content user created using your app falls under this category

    App Data: The images/videos/any other file that you download or store in the document directory for your app's functionality