@@ -25,7 +25,6 @@ class IterableKeychain {
25
25
26
26
wrapper. set ( data, forKey: Const . Keychain. Key. email)
27
27
}
28
-
29
28
}
30
29
31
30
var userId : String ? {
@@ -52,6 +51,7 @@ class IterableKeychain {
52
51
53
52
return data. flatMap { String ( data: $0, encoding: . utf8) }
54
53
}
54
+
55
55
set {
56
56
guard let token = newValue,
57
57
let data = token. data ( using: . utf8) else {
@@ -64,15 +64,18 @@ class IterableKeychain {
64
64
}
65
65
66
66
func getLastPushPayload( currentDate: Date ) -> [ AnyHashable : Any ] ? {
67
- guard let data = wrapper. data ( forKey: Const . Keychain. Key. lastPushPayload) else {
67
+ if isLastPushPayloadExpired ( currentDate: currentDate) {
68
+ wrapper. removeValue ( forKey: Const . Keychain. Key. lastPushPayload)
69
+ wrapper. removeValue ( forKey: Const . Keychain. Key. lastPushPayloadExpiration)
70
+
68
71
return nil
69
72
}
70
73
71
- let lastPushPayload = ( try ? JSONSerialization . jsonObject ( with : data ) ) as? [ AnyHashable : Any ]
72
-
73
- // check for expiration here
74
+ if let data = wrapper . data ( forKey : Const . Keychain . Key . lastPushPayload ) {
75
+ return ( try ? JSONSerialization . jsonObject ( with : data ) ) as? [ AnyHashable : Any ]
76
+ }
74
77
75
- return lastPushPayload
78
+ return nil
76
79
}
77
80
78
81
func setLastPushPayload( _ payload: [ AnyHashable : Any ] ? , withExpiration expiration: Date ? ) {
@@ -94,4 +97,14 @@ class IterableKeychain {
94
97
// MARK: - PRIVATE/INTERNAL
95
98
96
99
private let wrapper : KeychainWrapper
100
+
101
+ private func isLastPushPayloadExpired( currentDate: Date ) -> Bool {
102
+ // get expiration here
103
+
104
+ guard let expiration = wrapper. data ( forKey: Const . Keychain. Key. lastPushPayloadExpiration) as? Date else {
105
+ return false
106
+ }
107
+
108
+ return !( expiration. timeIntervalSinceReferenceDate > currentDate. timeIntervalSinceReferenceDate)
109
+ }
97
110
}
0 commit comments