Make files accessible when app in background

pull/4298/head
Krypto Pank 3 years ago
parent 8eada2e96a
commit 6935749273
  1. 9
      AlphaWallet/Core/Coordinators/Alerts/StorageType.swift
  2. 18
      AlphaWallet/Core/Types/RealmStore.swift
  3. 16
      AlphaWallet/Tokens/Types/TokenObject.swift

@ -77,6 +77,7 @@ struct FileStorage: StorageType {
do {
try data.write(to: url, options: .atomicWrite)
try url.addSkipBackupAttributeToItemAtURL()
try url.addProtectionKeyNone()
result = true
} catch {
@ -116,4 +117,12 @@ extension URL {
try self.setResourceValues(resourceValues)
}
mutating func addProtectionKeyNone() throws {
guard FileManager.default.fileExists(atPath: relativePath) else { return }
try FileManager.default.setAttributes([
FileAttributeKey.protectionKey: FileProtectionType.none
], ofItemAtPath: relativePath)
}
}

@ -10,19 +10,25 @@ import Foundation
final class RealmStore {
private let queue: DispatchQueue
private let config: Realm.Configuration
private let realm: Realm
public init(queue: DispatchQueue = DispatchQueue(label: "RealmStore.syncQueue", qos: .background), realm: Realm) {
public init(queue: DispatchQueue = DispatchQueue(label: "com.RealmStore.syncQueue", qos: .background), realm: Realm) {
self.queue = queue
self.realm = realm
self.config = realm.configuration
}
func performSync(_ callback: (Realm) -> Void) {
dispatchPrecondition(condition: .notOnQueue(queue))
queue.sync { [unowned self] in
autoreleasepool {
let realm = self.realm.threadSafe
callback(realm)
if Thread.isMainThread {
callback(realm)
} else {
dispatchPrecondition(condition: .notOnQueue(queue))
queue.sync { [unowned self] in
autoreleasepool {
let realm = try! Realm(configuration: config)
callback(realm)
}
}
}
}

@ -383,6 +383,20 @@ extension Wallet.functional {
static func realm(forAccount account: Wallet) -> Realm {
let migration = MigrationInitializer(account: account)
migration.perform()
return try! Realm(configuration: migration.config)
let realm = try! Realm(configuration: migration.config)
let realmUrl = migration.config.fileURL!
let realmUrls = [
realmUrl,
realmUrl.appendingPathExtension("lock"),
realmUrl.appendingPathExtension("note"),
realmUrl.appendingPathExtension("management")
]
for each in realmUrls {
try? FileManager.default.setAttributes([FileAttributeKey.protectionKey: FileProtectionType.none], ofItemAtPath: each.relativePath)
}
return realm
}
}

Loading…
Cancel
Save