import Flutter import UIKit class SceneDelegate: FlutterSceneDelegate { override func scene( _ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions ) { super.scene(scene, willConnectTo: session, options: connectionOptions) guard let windowScene = scene as? UIWindowScene, let window = windowScene.windows.first, let flutterVC = window.rootViewController as? FlutterViewController else { return } setupBackupChannel(messenger: flutterVC.binaryMessenger) } /// Registers the com.mnsoft.pailot/backup MethodChannel so Dart can call /// NSURLIsExcludedFromBackupKey on the messages storage directory. private func setupBackupChannel(messenger: FlutterBinaryMessenger) { let channel = FlutterMethodChannel( name: "com.mnsoft.pailot/backup", binaryMessenger: messenger ) channel.setMethodCallHandler { (call, result) in guard call.method == "excludeFromBackup" else { result(FlutterMethodNotImplemented) return } guard let path = call.arguments as? String else { result(FlutterError(code: "INVALID_ARG", message: "path argument required", details: nil)) return } var url = URL(fileURLWithPath: path) var values = URLResourceValues() values.isExcludedFromBackup = true do { try url.setResourceValues(values) result(nil) } catch { result(FlutterError(code: "SET_FAILED", message: error.localizedDescription, details: nil)) } } } }