XuqmGroup-iOSSDK/Sources/XuqmLicenseSDK/LicenseFileReader.swift

23 行
712 B
Swift

import Foundation
import XuqmCoreSDK
public enum LicenseFileReader {
public static func read() -> LicenseFile? {
guard let url = Bundle.main.url(forResource: "license", withExtension: "xuqm", subdirectory: "xuqm"),
let encrypted = try? String(contentsOf: url, encoding: .utf8) else {
return nil
}
return parse(encrypted)
}
static func parse(_ encrypted: String) -> LicenseFile? {
guard let json = try? LicenseFileCrypto.decrypt(encrypted),
let data = json.data(using: .utf8),
let file = try? JSONDecoder().decode(LicenseFile.self, from: data) else {
return nil
}
return file
}
}