Skip to content

Commit

Permalink
fix: sdk wrappers not having device token registered because of appli…
Browse files Browse the repository at this point in the history
…cation lifecycle (#285)
  • Loading branch information
Shahroz16 committed May 12, 2023
1 parent 4bc8ae3 commit da7fc51
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 150 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-sample-apps.yml
Expand Up @@ -51,7 +51,7 @@ jobs:
- name: pod install if app uses CocoaPods
if: steps.check_podfile_exists.outputs.files_exists == 'true'
run: pod install
run: pod install --repo-update

- name: Install tools for Fastlane build to use
run: brew install xcbeautify
Expand Down
20 changes: 19 additions & 1 deletion Sources/Common/DIGraph.swift
Expand Up @@ -18,10 +18,28 @@ public class DIGraph {
DIGraph.shared.override(mockOffRoadWheels, OffRoadWheels.self)
```
*/
public func override<Value: Any>(value: Value, forType type: Value.Type) {
public func override<T: Any>(value: T, forType type: T.Type) {
overrides[String(describing: type)] = value
}

// Retrieves an overridden instance of a specified type from the `overrides` dictionary.
// If an overridden instance exists and can be cast to the specified type, it is returned; otherwise, nil is returned.
public func getOverriddenInstance<T: Any>() -> T? {
// Get the type name as the key for the dictionary.
let typeName = String(describing: T.self)

guard overrides[typeName] != nil else {
return nil // no override set. Quit early.
}

// Get and cast the overridden instance from the dictionary.
guard let overriddenInstance = overrides[typeName] as? T else {
fatalError("Failed to cast overridden instance to type '\(typeName)'.")
}

return overriddenInstance
}

/**
Reset graph. Meant to be used in `tearDown()` of tests.
*/
Expand Down
9 changes: 9 additions & 0 deletions Sources/Common/Store/GlobalDataStore.swift
Expand Up @@ -40,6 +40,15 @@ public class CioGlobalDataStore: GlobalDataStore {
self.keyValueStorage.switchToGlobalDataStore()
}

// How to get instance before DI graph is constructed
public static func getInstance() -> GlobalDataStore {
let newInstance = UserDefaultsKeyValueStorage(
sdkConfig: SdkConfig.Factory.create(siteId: "", apiKey: "", region: .US),
deviceMetricsGrabber: DeviceMetricsGrabberImpl()
)
return CioGlobalDataStore(keyValueStorage: newInstance)
}

public func deleteAll() {
keyValueStorage.deleteAll()
}
Expand Down

0 comments on commit da7fc51

Please sign in to comment.