Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sdk wrappers not having device token registered because of application lifecycle #285

Merged
merged 27 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8895cd7
test
Shahroz16 Apr 2, 2023
8fab6fa
auto generated files
Shahroz16 Apr 2, 2023
bf1a26a
sourcery
Shahroz16 Apr 2, 2023
1e770f2
remove unused import and added check for shared error
Shahroz16 Apr 12, 2023
662fc50
lint and generate
Shahroz16 Apr 12, 2023
c45b9ce
Merge branch 'main' of github.com:customerio/customerio-ios into shah…
Shahroz16 Apr 18, 2023
4807e85
refactor: make getting instances of classes before SDK initialization…
levibostian Apr 18, 2023
e5e2c8e
added comments and refactored name
Shahroz16 Apr 18, 2023
c6755d3
autogenerate
Shahroz16 Apr 18, 2023
b021b6d
added support to store device token and register on sdk init
Shahroz16 Apr 18, 2023
0256a46
autogenerate
Shahroz16 Apr 18, 2023
d0e37f5
autogenerate
Shahroz16 Apr 18, 2023
c0cce41
autogenerate
Shahroz16 Apr 18, 2023
36ee48e
autogenerate
Shahroz16 Apr 18, 2023
eb701ba
added global datastore support in modules
Shahroz16 Apr 18, 2023
edb46ab
Merge branch 'main' of github.com:customerio/customerio-ios into shah…
Shahroz16 Apr 18, 2023
3dbc9bd
updated method to avoid duplicate requests in native
Shahroz16 Apr 19, 2023
fa90fa0
throw error in case of cast failure
Shahroz16 Apr 19, 2023
d9807d0
Merge branch 'main' of github.com:customerio/customerio-ios into shah…
Shahroz16 Apr 19, 2023
01f66a4
remove global data store from ModuleTopLevelObject
levibostian Apr 20, 2023
02002b7
Merge branch 'main' into shahroz-old-token-fix
levibostian Apr 20, 2023
ef7510a
Merge branch 'main' of github.com:customerio/customerio-ios into shah…
Shahroz16 Apr 22, 2023
1a5bffb
Merge branch 'main' of github.com:customerio/customerio-ios into shah…
Shahroz16 May 3, 2023
d23bbf8
Merge branch 'main' of github.com:customerio/customerio-ios into shah…
Shahroz16 May 10, 2023
423328a
update globaldatastore
Shahroz16 May 10, 2023
fa1523e
fixed tests
Shahroz16 May 10, 2023
2cfd1ba
autogen
Shahroz16 May 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -22,10 +22,28 @@
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)'.")

Check warning on line 41 in Sources/Common/DIGraph.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Common/DIGraph.swift#L41

Added line #L41 was not covered by tests
}

return overriddenInstance
}

/**
Reset graph. Meant to be used in `tearDown()` of tests.
*/
Expand Down
16 changes: 14 additions & 2 deletions Sources/Common/Store/GlobalDataStore.swift
Expand Up @@ -12,6 +12,14 @@ public protocol GlobalDataStore: AutoMockable {
func deleteAll()
}

/*
A datastore that is not tied to a specific site-id. This is data that is to be shared across all site-ids.

For example, device tokens. Device tokens are tied to a device and therefore, the value can be used between many different site-ids.

At this time, this object is added to the DI graph as that is still the preferred way to get an instance of it as it makes automated tests easier to write. However, for some use cases you need to get an instance of this class before the DI graph is constructed. In those scenarios, this class provides a way to get an instance not from the DI graph.
*/

// sourcery: InjectRegister = "GlobalDataStore"
public class CioGlobalDataStore: GlobalDataStore {
private let keyValueStorage: KeyValueStorage
Expand All @@ -34,10 +42,14 @@ public class CioGlobalDataStore: GlobalDataStore {
}
}

public init(keyValueStorage: KeyValueStorage) {
// constructor for automated tests to inject dependencies and also the constructor used by DI graph
public init(keyValueStorage: GlobalKeyValueStorage) {
self.keyValueStorage = keyValueStorage
}

self.keyValueStorage.switchToGlobalDataStore()
// How to get instance before DI graph is constructed
public static func getInstance() -> GlobalDataStore {
CioGlobalDataStore(keyValueStorage: GlobalKeyValueStorage.getInstance())
}

public func deleteAll() {
Expand Down
19 changes: 19 additions & 0 deletions Sources/Common/Util/KeyValueStorage.swift
@@ -1,5 +1,24 @@
import Foundation

/**
A version of KeyValueStorage that does not store data to a specific site-id. The data stored here is meant to be shared amongst all site-ids.
*/
// sourcery: InjectRegister = "GlobalKeyValueStorage"
public class GlobalKeyValueStorage: UserDefaultsKeyValueStorage {
// Used for automated tests
override init(siteId: SiteId, deviceMetricsGrabber: DeviceMetricsGrabber) {
super.init(siteId: siteId, deviceMetricsGrabber: deviceMetricsGrabber)

switchToGlobalDataStore()
}

public static func getInstance() -> GlobalKeyValueStorage {
let newInstance = GlobalKeyValueStorage(siteId: "", deviceMetricsGrabber: DeviceMetricsGrabberImpl())
newInstance.switchToGlobalDataStore()
return newInstance
}
}

/**
Stores data in key/value pairs.
*/
Expand Down