Prevent app from backing up documents folder?

后端 未结 2 1467
长发绾君心
长发绾君心 2020-12-25 08:59

I\'m trying to prevent my app backing up files to iCloud but have become completely confused and a little lost.

-EDIT-

I\'ve updated this to reflect the chan

2条回答
  •  旧巷少年郎
    2020-12-25 09:46

    In Swift:

    //Path of document directory
    var docPathAry : NSArray! = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
    var docDirPathStr: AnyObject? = docPathAry.count > 0 ? docPathAry[0] : nil
    
    self.addSkipBackupAttributeToItemAtURL(NSURL.fileURLWithPath(docDirPathStr as NSString))
    

    and:

    func addSkipBackupAttributeToItemAtURL(URL: NSURL!) -> Bool {
        assert(NSFileManager.defaultManager().fileExistsAtPath(URL.path))
        var err : NSError? = nil
        var success : Bool! = URL.setResourceValue(NSNumber.numberWithBool(true), forKey: NSURLIsExcludedFromBackupKey, error: &err)
    
        if(!success) {
            println("Error excluding \(URL.lastPathComponent) from backup\(err) ")
        }
    
        return success
    }
    

提交回复
热议问题