ios - Realm can't decrypt database error in background thread -


i using realm objective-c swift supporting ios7 in app.

i use function write block of code realm in background thread. wanted add encryption modified function so:

  class func updaterealmwithblockinbackground(block: () -> void) {     let priority = dispatch_queue_priority_default     dispatch_async(dispatch_get_global_queue(priority, 0)) {         {           let config = rlmrealmconfiguration.defaultconfiguration()           config.encryptionkey = utils.getkey()           let realm = try rlmrealm(configuration: config)            realm.beginwritetransaction()           block()           realm.commitwritetransaction()          } catch {           dispatch_async(dispatch_get_main_queue(), {             txnotificationsystem.postglobalnotification(text: "\(error)", textcolor: uicolor.redcolor())           })         }     }   } 

i getting error code 2: unable decrypt realm.

if use 1 write on main thread don't seem getting error.

anyone know why it's giving me error ?

if realm wasn't encrypted before, can't add encryption configuring encryption key. realm assume file on disk encrypted , try decrypt it.

you'll need open realm without encryption key , use - [rlmrealm writecopytopath:encryptionkey:error:] write encrypted copy. can delete original unencrypted .realm file , open encrypted copy encryption key set.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -