native_data_protection
Set iOS file protection and exclude files from backups in DartNative.
Install
Add to your DartNative app's pubspec.yaml:
dependencies:
native_data_protection:
hosted: https://dartpub.dev
version: ^0.1.1
Run dn pub get, then rebuild the app to link the native plugin. Use the generated plugin registrant provided by your DartNative app template.
Use
import 'package:native_data_protection/native_data_protection.dart';
// The directory must already exist inside your app's data container.
void protectFiles(String directoryPath) {
final files = NativeDataProtection();
files.protect(
directoryPath,
protection: NativeFileProtection.complete,
excludeFromBackup: true,
recursive: true,
);
final status = files.status(directoryPath);
print(status.protection);
}
Notes
- iOS only, with a native deployment target of iOS 15+. Your DartNative SDK may require a newer OS.
- Paths must already exist inside the app's data container. Symlinks and outside paths are rejected.
- Protection defaults to
completeand backup exclusion defaults totrue. Applied settings are checked; failures throwDataProtectionException. - Recursive changes include hidden files and are not atomic. Coordinate file writes, and test protection on a physical device: the simulator does not expose every protection attribute.
See API notes for protection policies and filesystem behavior.
MIT license.