accessAppleScopedResource method

Future<void> accessAppleScopedResource(
  1. Future<void> action(
    1. bool hasAccess,
    2. FcFilePickerPath pickerPath
    )
)

Implementation

Future<void> accessAppleScopedResource(
    Future<void> Function(bool hasAccess, FcFilePickerPath pickerPath)
        action) async {
  if (uri == null || path == null) {
    return;
  }
  if (!Platform.isIOS && !Platform.isMacOS) {
    return;
  }
  bool hasAccess = false;
  try {
    hasAccess =
        await _plugin.startAccessingSecurityScopedResourceWithURL(uri!);
    await action(hasAccess, this);
  } finally {
    if (hasAccess) {
      await _plugin.stopAccessingSecurityScopedResourceWithURL(uri!);
    }
  }
}