diff --git a/Adamant/Debug.entitlements b/Adamant/Debug.entitlements
index 7713a96e4..8e1de5348 100644
--- a/Adamant/Debug.entitlements
+++ b/Adamant/Debug.entitlements
@@ -20,6 +20,10 @@
$(TeamIdentifierPrefix)$(CFBundleIdentifier)
com.apple.security.app-sandbox
+ com.apple.security.application-groups
+
+ group.adamant.adamant-messenger
+
com.apple.security.device.camera
com.apple.security.network.client
diff --git a/Adamant/Release.entitlements b/Adamant/Release.entitlements
index 854da1316..85b260349 100644
--- a/Adamant/Release.entitlements
+++ b/Adamant/Release.entitlements
@@ -20,6 +20,10 @@
$(TeamIdentifierPrefix)$(CFBundleIdentifier)
com.apple.security.app-sandbox
+ com.apple.security.application-groups
+
+ group.adamant.adamant-messenger
+
com.apple.security.device.camera
com.apple.security.network.client
diff --git a/CommonKit/Sources/CommonKit/Services/KeychainStore.swift b/CommonKit/Sources/CommonKit/Services/KeychainStore.swift
index e6fbd85dd..9be433fe9 100644
--- a/CommonKit/Sources/CommonKit/Services/KeychainStore.swift
+++ b/CommonKit/Sources/CommonKit/Services/KeychainStore.swift
@@ -23,10 +23,12 @@ public final class KeychainStore: SecuredStore {
private let oldKeychainService = "im.adamant"
private let migrationKey = "migrated"
private let migrationValue = "2"
+ private lazy var userDefaults = UserDefaults(suiteName: sharedGroup)
public init(secureStorage: SecureStorageProtocol) {
self.secureStorage = secureStorage
+ migrateUserDefaultsIfNeeded()
clearIfNeeded()
configure()
migrateIfNeeded()
@@ -90,11 +92,13 @@ private extension KeychainStore {
}
func clearIfNeeded() {
- let isFirstRun = !UserDefaults.standard.bool(forKey: firstRun)
+ guard let userDefaults = userDefaults else { return }
+
+ let isFirstRun = !userDefaults.bool(forKey: firstRun)
guard isFirstRun else { return }
- UserDefaults.standard.set(true, forKey: firstRun)
+ userDefaults.set(true, forKey: firstRun)
purgeStore()
}
@@ -211,6 +215,15 @@ private extension KeychainStore {
setValue(value, for: key)
}
}
+
+ func migrateUserDefaultsIfNeeded() {
+ let migrated = KeychainStore.keychain[migrationKey]
+ guard migrated != migrationValue else { return }
+
+ let value = UserDefaults.standard.bool(forKey: firstRun)
+ userDefaults?.set(value, forKey: firstRun)
+ }
}
private let firstRun = "app.firstRun"
+private let sharedGroup = "group.adamant.adamant-messenger"
diff --git a/MessageNotificationContentExtension/Debug.entitlements b/MessageNotificationContentExtension/Debug.entitlements
index 6aa188f4e..630574fd2 100644
--- a/MessageNotificationContentExtension/Debug.entitlements
+++ b/MessageNotificationContentExtension/Debug.entitlements
@@ -4,6 +4,10 @@
com.apple.security.app-sandbox
+ com.apple.security.application-groups
+
+ group.adamant.adamant-messenger
+
com.apple.security.network.client
keychain-access-groups
diff --git a/MessageNotificationContentExtension/Release.entitlements b/MessageNotificationContentExtension/Release.entitlements
index 155317021..125fd8842 100644
--- a/MessageNotificationContentExtension/Release.entitlements
+++ b/MessageNotificationContentExtension/Release.entitlements
@@ -4,6 +4,10 @@
com.apple.security.app-sandbox
+ com.apple.security.application-groups
+
+ group.adamant.adamant-messenger
+
com.apple.security.network.client
keychain-access-groups
diff --git a/NotificationServiceExtension/Debug.entitlements b/NotificationServiceExtension/Debug.entitlements
index 6aa188f4e..630574fd2 100644
--- a/NotificationServiceExtension/Debug.entitlements
+++ b/NotificationServiceExtension/Debug.entitlements
@@ -4,6 +4,10 @@
com.apple.security.app-sandbox
+ com.apple.security.application-groups
+
+ group.adamant.adamant-messenger
+
com.apple.security.network.client
keychain-access-groups
diff --git a/NotificationServiceExtension/Release.entitlements b/NotificationServiceExtension/Release.entitlements
index 155317021..125fd8842 100644
--- a/NotificationServiceExtension/Release.entitlements
+++ b/NotificationServiceExtension/Release.entitlements
@@ -4,6 +4,10 @@
com.apple.security.app-sandbox
+ com.apple.security.application-groups
+
+ group.adamant.adamant-messenger
+
com.apple.security.network.client
keychain-access-groups
diff --git a/TransferNotificationContentExtension/Debug.entitlements b/TransferNotificationContentExtension/Debug.entitlements
index 6aa188f4e..630574fd2 100644
--- a/TransferNotificationContentExtension/Debug.entitlements
+++ b/TransferNotificationContentExtension/Debug.entitlements
@@ -4,6 +4,10 @@
com.apple.security.app-sandbox
+ com.apple.security.application-groups
+
+ group.adamant.adamant-messenger
+
com.apple.security.network.client
keychain-access-groups
diff --git a/TransferNotificationContentExtension/Release.entitlements b/TransferNotificationContentExtension/Release.entitlements
index 155317021..125fd8842 100644
--- a/TransferNotificationContentExtension/Release.entitlements
+++ b/TransferNotificationContentExtension/Release.entitlements
@@ -4,6 +4,10 @@
com.apple.security.app-sandbox
+ com.apple.security.application-groups
+
+ group.adamant.adamant-messenger
+
com.apple.security.network.client
keychain-access-groups