Securing Data in iTunes Backups

suggest change

If we want our app data to be protected against iTunes backups, we have to skip our app data from being backed up in iTunes.

Whenever iOS device backed up using iTunes on macOS, all the data stored by all the apps is copied in that backup and stored on backing computer.

But we can exclude our app data from this backup using URLResourceKey.isExcludedFromBackupKey key.

Here is the directory structure of our app:

Note: Generally sensitive data is stored in ‘Application Support’ directory.

e.g. If we want to exclude all our data stored in Application Support directory then we can use above mentioned key as follow:

let urls = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)
let baseURL = urls[urls.count-1];

let bundleIdentifier = Bundle.main.object(forInfoDictionaryKey: "CFBundleIdentifier") as! String
let pathURL = baseURL.appendingPathComponent(bundleIdentifier)
let persistentStoreDirectoryPath = pathURL.path
if !FileManager.default.fileExists(atPath: persistentStoreDirectoryPath) {
    do {
        try FileManager.default.createDirectory(atPath: path, withIntermediateDirectories: true, attributes: nil)  
    }catch {
        //handle error
    }
}
let dirURL = URL.init(fileURLWithPath: persistentStoreDirectoryPath, isDirectory: true)
do {
    try (dirURL as NSURL).setResourceValue((true), forKey: .isExcludedFromBackupKey)
} catch {
    //handle error
}

There are lots of tools available to see iTunes backups for all the backed up data to confirm whether above approach works or not.

iExplorer is good one to explore iTunes backups.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Security:
* Securing Data in iTunes Backups

Table Of Contents
12 UIView
15 UIColor
26 UIImage
28 CALayer
30 NSDate
40 iBeacon
49 NSTimer
79 NSURL
87 AWS SDK
96 NSData
101 Segues
104 EventKit
105 NSBundle
106 SiriKit
111 StoreKit
117 3D Touch
119 Keychain
122 Block
141 AirDrop
144 UISlider
145 Carthage
146 HealthKit
151 plist
157 MVVM
164 UIPhoenix
166 Simulator
168 NSArray
169 OpenGL
175 Core Data
179 MyLayout
180 UIFont
189 Security
200 Codable