Skip to content

Commit 08eb3d6

Browse files
committed
create new export function for userdefaults
1 parent d382298 commit 08eb3d6

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

swift-sdk/Internal/IterableUserDefaults.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,21 @@ class IterableUserDefaults {
8282
try? save(dict: payload, withKey: .payload, andExpiration: expiration)
8383
}
8484

85+
func getLastPushPayloadAndExpirationPair() -> (payload: [AnyHashable: Any]?, expiration: Date?)? {
86+
guard let encodedEnvelope = userDefaults.value(forKey: UserDefaultsKey.payload.value) as? Data else {
87+
return nil
88+
}
89+
90+
do {
91+
let envelope = try JSONDecoder().decode(Envelope.self, from: encodedEnvelope)
92+
let decoded = try JSONSerialization.jsonObject(with: envelope.payload, options: []) as? [AnyHashable: Any]
93+
94+
return (payload: decoded, envelope.expiration)
95+
} catch {
96+
return nil
97+
}
98+
}
99+
85100
// MARK: Private implementation
86101

87102
private let userDefaults: UserDefaults

0 commit comments

Comments
 (0)