iOS: Do not back up attribute?

后端 未结 3 1638
难免孤独
难免孤独 2020-12-15 05:20

Our app has recently been rejected for violating iOS Data Storage Guidelines about backing up files on iCloud.

I must mark data with the do not ba

3条回答
  •  一个人的身影
    2020-12-15 05:58

    Swift 5 version:

    func addSkipBackupAttributeTo(url constURL: URL) {
        do {
            // Need a mutable URL to call setResourceValues
            var url = constURL
            var resourceValues = URLResourceValues()
            resourceValues.isExcludedFromBackup = true
            try url.setResourceValues(resourceValues)
        } catch {
            print("Unable to set isExcludedFromBackup on \(constURL)")
        }
    }
    

    URLResourceValues keeps track of which values are modified and only writes those out, so it's fine to initialize a new object, set one key and call setResourceValues with it.

提交回复
热议问题