Skip to content

Commit 8ffd20f

Browse files
committed
have the rest of the SDK call on the new functions
1 parent b749a3b commit 8ffd20f

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

swift-sdk/Internal/InternalIterableAPI.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
4141
}
4242

4343
var lastPushPayload: [AnyHashable: Any]? {
44-
localStorage.getPayload(currentDate: dateProvider.currentDate)
44+
localStorage.getLastPushPayload(dateProvider.currentDate)
4545
}
4646

4747
var attributionInfo: IterableAttributionInfo? {

swift-sdk/Internal/LocalStorage.swift

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,22 @@ struct LocalStorage: LocalStorageProtocol {
7575
iterableUserDefaults.save(attributionInfo: attributionInfo, withExpiration: expiration)
7676
}
7777

78-
func getPayload(currentDate: Date) -> [AnyHashable: Any]? {
79-
iterableUserDefaults.getPayload(currentDate: currentDate)
78+
func getLastPushPayload(_ currentDate: Date) -> [AnyHashable: Any]? {
79+
return keychain.getLastPushPayload(currentDate: currentDate)
8080
}
8181

82-
func save(payload: [AnyHashable: Any]?, withExpiration expiration: Date?) {
83-
iterableUserDefaults.save(payload: payload, withExpiration: expiration)
82+
func saveLastPushPayload(_ payload: [AnyHashable: Any]?, withExpiration expiration: Date?) {
83+
keychain.setLastPushPayload(payload, withExpiration: expiration)
8484
}
8585

8686
func upgrade() {
8787
ITBInfo()
8888

8989
/// moves `email`, `userId`, and `authToken` from `UserDefaults` to `IterableKeychain`
9090
moveAuthDataFromUserDefaultsToKeychain()
91+
92+
/// moves `lastPushPayload` from `UserDefaults` to `IterableKeychain`
93+
moveLastPushPayloadFromUserDefaultsToKeychain()
9194
}
9295

9396
// MARK: Private
@@ -117,4 +120,13 @@ struct LocalStorage: LocalStorageProtocol {
117120
ITBInfo("UPDATED: moved userId from UserDefaults to IterableKeychain")
118121
}
119122
}
123+
124+
private func moveLastPushPayloadFromUserDefaultsToKeychain() {
125+
// using current date rather than `DateProvider` for convenience
126+
if let (userDefaultLastPushPayload, expiration) = iterableUserDefaults.getLastPushPayloadAndExpirationPair() {
127+
keychain.setLastPushPayload(userDefaultLastPushPayload, withExpiration: expiration)
128+
129+
ITBInfo("UPDATED: moved lastPushPayload from UserDefaults to IterableKeychain")
130+
}
131+
}
120132
}

swift-sdk/Internal/LocalStorageProtocol.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ protocol LocalStorageProtocol {
1414
var offlineMode: Bool { get set }
1515
func getAttributionInfo(currentDate: Date) -> IterableAttributionInfo?
1616
func save(attributionInfo: IterableAttributionInfo?, withExpiration expiration: Date?)
17-
func getPayload(currentDate: Date) -> [AnyHashable: Any]?
18-
func save(payload: [AnyHashable: Any]?, withExpiration: Date?)
17+
func getLastPushPayload(_ currentDate: Date) -> [AnyHashable: Any]?
18+
func saveLastPushPayload(_ payload: [AnyHashable: Any]?, withExpiration expiration: Date?)
1919
func upgrade()
2020
}
2121

0 commit comments

Comments
 (0)