get infura key from cloud kit

This commit is contained in:
ivan grachev 2023-11-05 17:12:47 +03:00
parent fece2efec5
commit cde9f5e647
4 changed files with 39 additions and 2 deletions

View File

@ -7,10 +7,9 @@ struct Nodes {
private static let infuraKey: String = {
if let path = Bundle.main.path(forResource: "shared", ofType: "plist"),
let dict = NSDictionary(contentsOfFile: path) as? [String: AnyObject],
let infuraKey = dict["InfuraKey"] as? String {
let infuraKey = dict["InfuraKey"] as? String, !infuraKey.isEmpty {
return infuraKey
} else {
// TODO: get from CloudKit
// TODO: hande infura key not being bundled
return ""
}

View File

@ -1,6 +1,7 @@
// Copyright © 2023 Tokenary. All rights reserved.
import Foundation
import CloudKit
class ConfigurationService {
@ -25,6 +26,10 @@ class ConfigurationService {
if !shouldUpdateApp {
getConfiguration()
}
getInfuraKeyFromCloudKit { infuraKey in
// TODO: keep latest version in defaults and make it accessible to Nodes
print(infuraKey)
}
}
func didPromptToUpdate() {
@ -45,4 +50,21 @@ class ConfigurationService {
dataTask.resume()
}
private func getInfuraKeyFromCloudKit(completion: @escaping (String) -> Void) {
let container = CKContainer(identifier: "iCloud.tokenary")
let publicDatabase = container.publicCloudDatabase
let predicate = NSPredicate(value: true)
let query = CKQuery(recordType: "Config", predicate: predicate)
publicDatabase.fetch(withQuery: query) { result in
if case .success(let success) = result,
case let .success(record) = success.matchResults.first?.1,
let infuraKeys = record["infuraKeys"] as? [String],
let infuraKey = infuraKeys.first {
DispatchQueue.main.async {
completion(infuraKey)
}
}
}
}
}

View File

@ -6,6 +6,14 @@
<array>
<string>applinks:tokenary.io</string>
</array>
<key>com.apple.developer.icloud-container-identifiers</key>
<array>
<string>iCloud.tokenary</string>
</array>
<key>com.apple.developer.icloud-services</key>
<array>
<string>CloudKit</string>
</array>
<key>com.apple.security.application-groups</key>
<array>
<string>group.io.tokenary</string>

View File

@ -6,6 +6,14 @@
<array>
<string>applinks:tokenary.io</string>
</array>
<key>com.apple.developer.icloud-container-identifiers</key>
<array>
<string>iCloud.tokenary</string>
</array>
<key>com.apple.developer.icloud-services</key>
<array>
<string>CloudKit</string>
</array>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.application-groups</key>