Skip to content

Commit

Permalink
refactor: fetch RMCSDK version from plist only once form RMC Bundle (…
Browse files Browse the repository at this point in the history
…SDKCF-6851)
  • Loading branch information
Esakkiraja-Pothikannan committed Jan 24, 2024
1 parent 0ef89a2 commit 2309ecf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Sources/REventLogger/REvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ struct REvent: Codable, Equatable {
self.deviceModel = environment.deviceModel
self.deviceBrand = environment.deviceBrand
self.deviceName = environment.deviceName
self.rmcSdks = environment.rmcSDKs
self.firstOccurrenceOn = Date().timeIntervalSince1970
self.eventType = eventType
self.sourceName = sourceName
self.sourceVersion = sourceVersion
self.errorCode = errorCode
self.errorMessage = errorMessage
self.info = info
self.rmcSdks = Bundler.rmcSdks
}
}

Expand Down
26 changes: 14 additions & 12 deletions Sources/REventLogger/REventLoggerEnvironment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ private enum BundleKeys {
static let bundleIdentifier = "CFBundleIdentifier"
static let shortVersion = "CFBundleShortVersionString"
static let displayName = "CFBundleDisplayName"
static let rmcBundleName = "RMC_RMC.bundle"
static let rmcVersionsInfoList = "RmcInfo"
}

final class REventLoggerEnvironment {
private let bundle: BundleProtocol
private var rmcSDKsVersion: [String: String]?

init(bundle: BundleProtocol = Bundle.main) {
self.bundle = bundle
Expand Down Expand Up @@ -49,26 +52,25 @@ final class REventLoggerEnvironment {
bundle.deviceBrand()
}

var rmcBundle: Bundle? {
.rmcResources
var rmcSDKs: [String: String]? {
if rmcSDKsVersion == nil {
rmcSDKsVersion = getRMCSDKsVersion()
}
return rmcSDKsVersion
}

var rmcSdks: [String: String]? {
rmcBundle?.getRMCSdks()
private func getRMCSDKsVersion() -> [String: String]? {
guard let path = Bundle.rmcBundle?.path(forResource: BundleKeys.rmcVersionsInfoList, ofType: "plist") else { return nil }
return NSDictionary(contentsOfFile: path) as? [String: String]
}
}

internal extension Bundle {
static var rmcResources: Bundle? {
guard let rmcBundleUrl = main.resourceURL?.appendingPathComponent("RMC_RMC.bundle"),
extension Bundle {
static var rmcBundle: Bundle? {
guard let rmcBundleUrl = main.resourceURL?.appendingPathComponent(BundleKeys.rmcBundleName),
let bundle = Bundle(url: rmcBundleUrl) else {
return nil
}
return bundle
}

fileprivate func getRMCSdks() -> [String: String]? {
guard let path = path(forResource: "RmcInfo", ofType: "plist") else { return nil }
return NSDictionary(contentsOfFile: path) as? [String: String]
}
}
4 changes: 0 additions & 4 deletions Sources/REventLogger/Utilities/Utility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,3 @@ extension NSError {
self.code == URLError.networkConnectionLost.rawValue
}
}

enum Bundler {
static let rmcSdks = REventLoggerEnvironment().rmcSdks
}

0 comments on commit 2309ecf

Please sign in to comment.