0

I have created a realm database, and I can fetch the data on my iOS application class on the mobile device. but I need to fetch data from the custom keyboard extension class of the same application. I got a realm. lock file operation not permitted error is thrown as

Error Domain=io.realm Code=3 "Failed to open file at path '/private/var/mobile/Containers/Shared/AppGroup/23DD1FD4-A291-4599-9D5F-84057FE6CF26/BigramFileShared.realm.lock': Operation not permitted" UserInfo={Error Code=3, NSFilePath=/private/var/mobile/Containers/Shared/AppGroup/23DD1FD4-A291-4599-9D5F-84057FE6CF26/BigramFileShared.realm.lock, Error Name=PermissionDenied, NSLocalizedDescription=Failed to open file at path '/private/var/mobile/Containers/Shared/AppGroup/23DD1FD4-A291-4599-9D5F-84057FE6CF26/BigramFileShared.realm.lock': Operation not permitted

I tried the input source:

let strpath = userDefaultAddress?.value(forKey: "shared_bigram_file_path")
let realmURL = URL(fileURLWithPath: strpath as! String )
let config = Realm.Configuration(fileURL: realmURL)
let realm = try! Realm()

// Get our Realm file's parent directory
let folderPath = realm.configuration.fileURL!.deletingLastPathComponent().path

// Disable file protection for this directory
try! FileManager.default.setAttributes([FileAttributeKey(rawValue: FileAttributeKey.protectionKey.rawValue): FileProtectionType.none], ofItemAtPath: folderPath)
        
do {
     let realm = try Realm(configuration: config)
     let results = realm.objects(IndianSpace.self)
   } catch {
            print("Error opening Realm: \(error)")
   }
PAVUNRAJ P
  • 21
  • 3
  • The code is little confusing; it builds a path to a Realm file, but the path is incomplete and then the code removes the last path component. We also don't know what `userDefaultAddress` resolves to and that really shouldn't be optional. It also doesn't appear the actual Realm file is named. Perhaps I am reading it wrong. Can you clarify? – Jay Aug 25 '23 at 18:01
  • Hi @Jay I stored the realm database at a file manager location on the mobile device, and I set the file_url path to use the userDefaultAddress property.The fileURLWithPath is: /private/var/mobile/Containers/Shared/AppGroup/23DD1FD4-A291-4599-9D5F-84057FE6CF26/BigramFileShared and here is a reference is open the realm database:https://www.mongodb.com/docs/realm/sdk/swift/realm-files/configure-and-open-a-realm/#open-a-realm-without-sync – PAVUNRAJ P Aug 26 '23 at 05:27
  • I don't think the code in the question does that (at least in my testing with copy paste)... and it's also an incomplete path as the realm filename is missing. Isn't the last part of the path removed, `deletingLastPathComponent`? I would add a breakpoint and step through the code and check those vars carefully and see what they actually resolve to. I could be totally wrong but please check it. – Jay Aug 26 '23 at 15:22

0 Answers0