diff --git a/Signal/src/Loki/Utilities/LokiPushNotificationManager.swift b/Signal/src/Loki/Utilities/LokiPushNotificationManager.swift index 8e8097f6e..5e417199d 100644 --- a/Signal/src/Loki/Utilities/LokiPushNotificationManager.swift +++ b/Signal/src/Loki/Utilities/LokiPushNotificationManager.swift @@ -13,7 +13,9 @@ final class LokiPushNotificationManager : NSObject { func register(with token: Data) { let hexEncodedToken = token.map { String(format: "%02.2hhx", $0) }.joined() let oldToken = UserDefaults.standard.string(forKey: "deviceToken") - if (hexEncodedToken == oldToken) { + let lastUploadTime = UserDefaults.standard.integer(forKey: "lastUploadTime") + let now = Int(Date().timeIntervalSince1970) + if hexEncodedToken == oldToken && now - lastUploadTime < 48 * 60 * 60 { Logger.info("Token is not changed, no need to upload") return } @@ -28,6 +30,7 @@ final class LokiPushNotificationManager : NSObject { return print("[Loki] An error occured during device token registration: \(json["message"] as? String ?? "nil").") } UserDefaults.standard.set(hexEncodedToken, forKey: "deviceToken") + UserDefaults.standard.set(now, forKey: "lastUploadTime") }, failure: { _, error in print("[Loki] Couldn't register device token.") })