mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 03:05:19 +00:00
Fix verification persistence on iOS when app backgrounds (#822)
* Fix verification persistence on iOS when app backgrounds (#785) Verification status was not being saved when the iOS app entered background state, causing verified contacts to lose their verification status after the app was closed. This happened because iOS can terminate backgrounded apps without calling applicationWillTerminate. Changes: - Add saveIdentityState() method to force-save identity data without stopping services - Call saveIdentityState() when iOS app enters background state - Refactor applicationWillTerminate() to use new method - Fix selector name typo (appWillTerminate -> applicationWillTerminate) The verification data is now properly persisted to encrypted keychain storage whenever the app backgrounds, ensuring verification status persists across app launches. Fixes #785 * Save identity state during verification events --------- Co-authored-by: jack <jackjackbits@users.noreply.github.com>
This commit is contained in:
@@ -189,6 +189,10 @@ final class AppDelegate: NSObject, UIApplicationDelegate {
|
||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func applicationWillTerminate(_ application: UIApplication) {
|
||||
chatViewModel?.applicationWillTerminate()
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -720,7 +720,7 @@ final class ChatViewModel: ObservableObject, BitchatDelegate {
|
||||
)
|
||||
NotificationCenter.default.addObserver(
|
||||
self,
|
||||
selector: #selector(appWillTerminate),
|
||||
selector: #selector(applicationWillTerminate),
|
||||
name: NSApplication.willTerminateNotification,
|
||||
object: nil
|
||||
)
|
||||
@@ -776,7 +776,7 @@ final class ChatViewModel: ObservableObject, BitchatDelegate {
|
||||
)
|
||||
NotificationCenter.default.addObserver(
|
||||
self,
|
||||
selector: #selector(appWillTerminate),
|
||||
selector: #selector(applicationWillTerminate),
|
||||
name: UIApplication.willTerminateNotification,
|
||||
object: nil
|
||||
)
|
||||
@@ -3251,24 +3251,21 @@ final class ChatViewModel: ObservableObject, BitchatDelegate {
|
||||
// No-op; avoid forcing synchronize on resign
|
||||
}
|
||||
|
||||
/// Save identity state without stopping services (for backgrounding)
|
||||
func saveIdentityState() {
|
||||
// Force save any pending identity changes (verifications, favorites, etc)
|
||||
identityManager.forceSave()
|
||||
|
||||
// Verify identity key is still there
|
||||
_ = keychain.verifyIdentityKeyExists()
|
||||
}
|
||||
|
||||
@objc func applicationWillTerminate() {
|
||||
// Send leave message to all peers
|
||||
meshService.stopServices()
|
||||
|
||||
// Force save any pending identity changes (verifications, favorites, etc)
|
||||
identityManager.forceSave()
|
||||
|
||||
// Verify identity key is still there
|
||||
_ = keychain.verifyIdentityKeyExists()
|
||||
|
||||
// No need to force synchronize here
|
||||
|
||||
// Verify identity key after save
|
||||
_ = keychain.verifyIdentityKeyExists()
|
||||
}
|
||||
|
||||
@objc private func appWillTerminate() {
|
||||
// No need to force synchronize here
|
||||
|
||||
// Save identity state
|
||||
saveIdentityState()
|
||||
}
|
||||
|
||||
@MainActor
|
||||
@@ -4464,6 +4461,7 @@ final class ChatViewModel: ObservableObject, BitchatDelegate {
|
||||
|
||||
// Update secure storage with verified status
|
||||
identityManager.setVerified(fingerprint: fingerprint, verified: true)
|
||||
saveIdentityState()
|
||||
|
||||
// Update local set for UI
|
||||
verifiedFingerprints.insert(fingerprint)
|
||||
@@ -4476,7 +4474,7 @@ final class ChatViewModel: ObservableObject, BitchatDelegate {
|
||||
func unverifyFingerprint(for peerID: PeerID) {
|
||||
guard let fingerprint = getFingerprint(for: peerID) else { return }
|
||||
identityManager.setVerified(fingerprint: fingerprint, verified: false)
|
||||
identityManager.forceSave()
|
||||
saveIdentityState()
|
||||
verifiedFingerprints.remove(fingerprint)
|
||||
updateEncryptionStatus(for: peerID)
|
||||
}
|
||||
@@ -4685,7 +4683,7 @@ final class ChatViewModel: ObservableObject, BitchatDelegate {
|
||||
let short = fp.prefix(8)
|
||||
SecureLogger.info("🔐 Marking verified fingerprint: \(short)", category: .security)
|
||||
identityManager.setVerified(fingerprint: fp, verified: true)
|
||||
identityManager.forceSave()
|
||||
saveIdentityState()
|
||||
verifiedFingerprints.insert(fp)
|
||||
let name = unifiedPeerService.getPeer(by: peerID)?.nickname ?? resolveNickname(for: peerID)
|
||||
NotificationService.shared.sendLocalNotification(
|
||||
|
||||
Reference in New Issue
Block a user