Flutter Path Provider with Hive OS Error: Operation not permitted, errno = 1

Viewed 231

I am using Hive and Path Provider inside my app and on the simulator everything is working just fine. But when running my app on a real device (iPhone X, iOS 15) I get this error:

[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: FileSystemException: Creation failed, path = '/var/mobile/Containers/Data/Application/9B79CFB2-7AF9-4F2E-BD65-67950D247FEF/Documentshive_db' (OS Error: Operation not permitted, errno = 1)

This is the code where it is throwing the error:

static Future<void> init() async {
    var dir = await getApplicationDocumentsDirectory();
    // make sure it exists
    await dir.create(recursive: true);

    var dbPath = '${dir.path}hive_db';

    Hive
      ..init(dbPath)
      ..registerAdapter(HiveMedicamentAdapter())
      ..registerAdapter(HiveVitalsAdapter())
      ..registerAdapter(HiveDiscomfortAdapter())
      ..registerAdapter(HiveEmergencyContactAdapter())
      ..registerAdapter(HiveEventAdapter());

    await Hive.openBox<HiveMedicament>(HiveKeys.medicaments); // <- throws above error
    await Hive.openBox<HiveVitals>(HiveKeys.vitals);
    await Hive.openBox<List>(HiveKeys.discomforts);
    await Hive.openBox<bool>(HiveKeys.auth);
    await Hive.openBox<bool>(HiveKeys.syncLocalWithBackend);
    await Hive.openBox<HiveEmergencyContact>(HiveKeys.emergencyContacts);
    await Hive.openBox<String>(HiveKeys.pdfSecret);
    await Hive.openBox<HiveEvent>(HiveKeys.event);
  }

I searched for any Hive issues or path provider issues but couldn't find anything. What am I missing here? I thought Hive or Path Provider does not need any extra permissions.

Any help is appreciated! Let me know if you need more info!

0 Answers
Related