Skip to content

Commit 6c69b21

Browse files
committed
Update Core.swift to include deinit for removing notification observers
1 parent aef8e47 commit 6c69b21

File tree

3 files changed

+38
-33
lines changed

3 files changed

+38
-33
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [1.0.3]
6+
- Implemented deinit to remove notification observers when the player is deinitialized, ensuring proper resource cleanup.
7+
58
## [1.0.2]
69
- Fixed video_source_bitrate in variantChanged events.
710
- Fixed event transition calculations .
811

912
## [1.0.1]
10-
- Bug fixes and maintenance updates.
13+
- Fixed bugs and improved the accuracy of metrics parameter calculations during event transitions.
1114

1215
## [1.0.0]
1316

Sources/FastpixiOSVideoDataCore/MonitorMetrics/PlaybackEventHandler.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ public class PlybackPulseHadler {
99
public var dispatchNucleusEvent: NucleusState
1010
public var tokenId: String?
1111
public var actionableData: [String: Any]?
12-
public var sdkDetails: [String: Any]
1312
public var userData: [String: Any]
1413
public var previousBeaconData: [String: Any]?
1514
public var previousVideoState: [String: Any] = [:]
@@ -44,10 +43,6 @@ public class PlybackPulseHadler {
4443
self.actionableData = nucleusState.metadata
4544
self.tokenId = nucleusState.metadata["workspace_id"] as? String
4645
self.previousBeaconData = nil
47-
self.sdkDetails = [
48-
"fastpix_embed" : "fastpix-ios-core",
49-
"fastpix_embed_version" : "1.0.0",
50-
]
5146
self.userData = FastPixUserDefaults.getViewerCookie()
5247
self.getFastPixAPI = formulateBeaconUrl(workspace: self.tokenId ?? "", config: self.actionableData ?? [:])
5348
self.eventDispatcher = ConnectionHandler(api: self.getFastPixAPI ?? "")
@@ -71,7 +66,6 @@ public class PlybackPulseHadler {
7166
fetchedVideoState = self.dispatchNucleusEvent.getVideoData()
7267
}
7368
let mergedData = mergeDictionaries(
74-
self.sdkDetails,
7569
eventAttr,
7670
sessionData,
7771
deviceDetails,

Sources/FastpixiOSVideoDataCore/MonitorMetrics/core.swift

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -50,32 +50,32 @@ public class NucleusState {
5050
]
5151

5252
public init(key: String, passableMetadata: [String: Any], fetchPlayheadTime: @escaping () -> Int,
53-
fetchVideoState: @escaping () -> [String:Any]) {
54-
self.key = key
55-
self.metadata = passableMetadata["data"] as! [String : Any]
56-
self.utilMethods = commonMethods
57-
self.getVideoData = fetchVideoState
58-
self.getCurrentPlayheadTime = fetchPlayheadTime
59-
self.playerInitializationTime = commonMethods.now()
60-
self.isVideoPlaying = false
61-
self.isVideoBuffering = false
62-
self.isVideoSeeking = false
63-
self.isVideoErrorOccured = false
64-
self.playerDestroyed = false
65-
self.data = [
66-
"player_sequence_number": 1,
67-
"view_sequence_number": 1,
68-
"player_instance_id": commonMethods.getUUID().lowercased(),
69-
"beacon_domain": (passableMetadata["configDomain"] as? String) ?? "metrix.ws",
70-
"workspace_id": (self.metadata["workspace_id"] as? String) ?? "workspaceId"
71-
]
53+
fetchVideoState: @escaping () -> [String:Any]) {
54+
self.key = key
55+
self.metadata = passableMetadata["data"] as! [String : Any]
56+
self.utilMethods = commonMethods
57+
self.getVideoData = fetchVideoState
58+
self.getCurrentPlayheadTime = fetchPlayheadTime
59+
self.playerInitializationTime = commonMethods.now()
60+
self.isVideoPlaying = false
61+
self.isVideoBuffering = false
62+
self.isVideoSeeking = false
63+
self.isVideoErrorOccured = false
64+
self.playerDestroyed = false
65+
self.data = [
66+
"player_sequence_number": 1,
67+
"view_sequence_number": 1,
68+
"player_instance_id": commonMethods.getUUID().lowercased(),
69+
"beacon_domain": (passableMetadata["configDomain"] as? String) ?? "metrix.ws",
70+
"workspace_id": (self.metadata["workspace_id"] as? String) ?? "workspaceId"
71+
]
7272

73-
self.lastCheckedEventTime = 0
74-
self.dispatchEvent(event: "configureView", eventmetadata: [:])
75-
76-
NotificationCenter.default.addObserver(self, selector: #selector(appWillTerminate), name: UIApplication.willTerminateNotification, object: nil)
77-
NotificationCenter.default.addObserver(self, selector: #selector(appWillTerminate), name: UIScreen.didDisconnectNotification, object: nil)
78-
}
73+
self.lastCheckedEventTime = 0
74+
self.dispatchEvent(event: "configureView", eventmetadata: [:])
75+
76+
NotificationCenter.default.addObserver(self, selector: #selector(appWillTerminate), name: UIApplication.willTerminateNotification, object: nil)
77+
NotificationCenter.default.addObserver(self, selector: #selector(appWillTerminate), name: UIScreen.didDisconnectNotification, object: nil)
78+
}
7979

8080
func emitEvents(event: String, eventmetadata: [String: Any]) {
8181
let currentTime = commonMethods.now()
@@ -245,7 +245,15 @@ public class NucleusState {
245245
func emitPulse() {
246246
dispatchEvent(event: "pulse", eventmetadata: [:])
247247
}
248-
248+
249+
deinit {
250+
// Remove observer for app termination to avoid potential retain cycles or memory leaks
251+
NotificationCenter.default.removeObserver(self, name: UIApplication.willTerminateNotification, object: nil)
252+
253+
// Remove observer for screen disconnection
254+
NotificationCenter.default.removeObserver(self, name: UIScreen.didDisconnectNotification, object: nil)
255+
}
256+
249257
func refreshViewData() {
250258
self.data.keys.forEach { key in
251259
if key.hasPrefix("view_") {

0 commit comments

Comments
 (0)