|
@@ -1559,83 +1559,6 @@ import Photos
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// MARK: - *** TEST ***
|
|
|
-
|
|
|
- public class NKAccountFile: NSObject {
|
|
|
-
|
|
|
- struct Account: Codable {
|
|
|
- let url: String
|
|
|
- let user: String
|
|
|
- let alias: String?
|
|
|
- let avatar: String?
|
|
|
- }
|
|
|
-
|
|
|
- struct Apps: Codable {
|
|
|
- let apps: [String: [Account]]?
|
|
|
- }
|
|
|
-
|
|
|
- @objc func putShareAccounts(at url: URL, app: String, dataAccounts: [NKDataAccountFile]) -> Error? {
|
|
|
-
|
|
|
- var apps: [String : [Account]] = [:]
|
|
|
- var accounts: [Account] = []
|
|
|
-
|
|
|
- for dataAccount in dataAccounts {
|
|
|
- let account = Account(url: dataAccount.url, user: dataAccount.user, alias: dataAccount.alias, avatar: dataAccount.avatar)
|
|
|
- accounts.append(account)
|
|
|
- }
|
|
|
- apps[app] = accounts
|
|
|
-
|
|
|
- // Decode
|
|
|
- do {
|
|
|
- let data = try Data(contentsOf: url)
|
|
|
- let json = try JSONDecoder().decode(Apps.self, from: data)
|
|
|
- if let appsDecoder = json.apps {
|
|
|
- let otherApps = appsDecoder.filter({ $0.key != app })
|
|
|
- apps.merge(otherApps){(current, _) in current}
|
|
|
- }
|
|
|
- } catch { }
|
|
|
-
|
|
|
- // Encode
|
|
|
- do {
|
|
|
- let data = try JSONEncoder().encode(Apps(apps: apps))
|
|
|
- try data.write(to: url)
|
|
|
- data.printJson()
|
|
|
- } catch let error {
|
|
|
- return error
|
|
|
- }
|
|
|
- return nil
|
|
|
- }
|
|
|
-
|
|
|
- @objc func getShareAccount(at url: URL, application: UIApplication?) -> [NKDataAccountFile]? {
|
|
|
-
|
|
|
- var dataAccounts: [NKDataAccountFile] = []
|
|
|
-
|
|
|
- do {
|
|
|
- let data = try Data(contentsOf: url)
|
|
|
- let json = try JSONDecoder().decode(Apps.self, from: data)
|
|
|
- if let appsDecoder = json.apps {
|
|
|
- for appDecoder in appsDecoder {
|
|
|
- let app = appDecoder.key
|
|
|
- let accounts = appDecoder.value
|
|
|
- if let url = URL(string: app + "://"), let application = application, application.canOpenURL(url) {
|
|
|
- for account in accounts {
|
|
|
- if dataAccounts.first(where: { $0.url == account.url && $0.user == account.user }) == nil {
|
|
|
- let account = NKDataAccountFile(withUrl: account.url, user: account.user, alias: account.alias, avatar: account.avatar)
|
|
|
- dataAccounts.append(account)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } catch { }
|
|
|
-
|
|
|
- return dataAccounts.isEmpty ? nil : dataAccounts
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
extension Array where Element == URLQueryItem {
|
|
|
subscript(name: String) -> URLQueryItem? {
|
|
|
first(where: { $0.name == name })
|