From eb041b81f717bac61af943219078708bf616d28c Mon Sep 17 00:00:00 2001 From: Balamurugan Date: Tue, 17 Mar 2026 18:07:18 +0530 Subject: [PATCH 1/2] refactor: isolate SDK Realm configuration from host application MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - The SDK previously relied on Realm’s global default configuration, which could affect Realm usage in the host application. - This happened because the SDK did not restrict the Realm schema and used the shared configuration. - This is fixed by introducing a dedicated SDK Realm configuration with restricted `objectTypes` and ensuring the SDK always opens Realm using that configuration. References: https://github.com/realm/realm-swift/issues/2807 https://stackoverflow.com/questions/30492098/multiple-realms-with-multiple-data-models --- Source/Database/ObjectManager.swift | 2 +- Source/TPStreamsSDK.swift | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Source/Database/ObjectManager.swift b/Source/Database/ObjectManager.swift index 64d51da..45d5a75 100644 --- a/Source/Database/ObjectManager.swift +++ b/Source/Database/ObjectManager.swift @@ -9,7 +9,7 @@ import Foundation import RealmSwift public class ObjectManager { - let realm = try! Realm() + let realm = try! Realm(configuration: TPStreamsSDK.realmConfig) func add(object: T) { try! realm.write { diff --git a/Source/TPStreamsSDK.swift b/Source/TPStreamsSDK.swift index 650b7be..2065be9 100644 --- a/Source/TPStreamsSDK.swift +++ b/Source/TPStreamsSDK.swift @@ -37,6 +37,7 @@ import RealmSwift public class TPStreamsSDK { + internal static let realmConfig: Realm.Configuration = buildRealmConfig() internal static var orgCode: String? internal static var provider: Provider = .tpstreams internal static var authToken: String? @@ -86,7 +87,7 @@ public class TPStreamsSDK { } } - private static func initializeDatabase() { + private static func buildRealmConfig() -> Realm.Configuration { var config = Realm.Configuration( schemaVersion: 5, migrationBlock: { migration, oldSchemaVersion in @@ -94,12 +95,17 @@ public class TPStreamsSDK { // No manual migration needed. // Realm automatically handles newly added optional properties. } - } + }, + objectTypes: [LocalOfflineAsset.self] ) config.fileURL!.deleteLastPathComponent() config.fileURL!.appendPathComponent("TPStreamsPlayerSDK") config.fileURL!.appendPathExtension("realm") - Realm.Configuration.defaultConfiguration = config + return config + } + + private static func initializeDatabase() { + _ = Self.realmConfig } private static func removeIncompleteDownloads() { From 3f9ba8c8df0661a4c192f99084b477e8d1d7b300 Mon Sep 17 00:00:00 2001 From: Balamurugan Date: Tue, 17 Mar 2026 18:42:22 +0530 Subject: [PATCH 2/2] Fix AI comment --- Source/TPStreamsSDK.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Source/TPStreamsSDK.swift b/Source/TPStreamsSDK.swift index 2065be9..8760ad1 100644 --- a/Source/TPStreamsSDK.swift +++ b/Source/TPStreamsSDK.swift @@ -98,9 +98,10 @@ public class TPStreamsSDK { }, objectTypes: [LocalOfflineAsset.self] ) - config.fileURL!.deleteLastPathComponent() - config.fileURL!.appendPathComponent("TPStreamsPlayerSDK") - config.fileURL!.appendPathExtension("realm") + config.fileURL = config.fileURL? + .deletingLastPathComponent() + .appendingPathComponent("TPStreamsPlayerSDK") + .appendingPathExtension("realm") return config }