Skip to content

Commit

Permalink
Enable inter-SDK communication for setting super properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
zihejia committed Jul 19, 2024
1 parent e7869c4 commit 5d1e989
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Sources/MixpanelInstance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ open class MixpanelInstance: CustomDebugStringConvertible, FlushDelegate, AEDele
#if os(iOS) || os(tvOS) || os(visionOS)
let automaticEvents = AutomaticEvents()
#endif
private let registerSuperPropertiesNotificationName = Notification.Name("com.mixpanel.properties.register")
private let unregisterSuperPropertiesNotificationName = Notification.Name("com.mixpanel.properties.unregister")

convenience init(
apiToken: String?,
Expand Down Expand Up @@ -421,6 +423,18 @@ open class MixpanelInstance: CustomDebugStringConvertible, FlushDelegate, AEDele
selector: #selector(applicationWillEnterForeground(_:)),
name: UIApplication.willEnterForegroundNotification,
object: nil)
notificationCenter.addObserver(
self,
selector: #selector(handleSuperPropertiesRegistrationNotification(_:)),
name: registerSuperPropertiesNotificationName,
object: nil
)
notificationCenter.addObserver(
self,
selector: #selector(handleSuperPropertiesRegistrationNotification(_:)),
name: unregisterSuperPropertiesNotificationName,
object: nil
)
}
}
#elseif os(OSX)
Expand Down Expand Up @@ -632,6 +646,20 @@ open class MixpanelInstance: CustomDebugStringConvertible, FlushDelegate, AEDele
#endif
#endif // os(iOS)

@objc func handleSuperPropertiesRegistrationNotification(_ notification: Notification) {
guard let data = notification.userInfo else { return }

if notification.name.rawValue == registerSuperPropertiesNotificationName.rawValue {
guard let properties = data as? Properties else { return }
registerSuperProperties(properties)
} else {
for (key, _) in data {
if let keyToUnregister = key as? String {
unregisterSuperProperty(keyToUnregister)
}
}
}
}
}

extension MixpanelInstance {
Expand Down

0 comments on commit 5d1e989

Please sign in to comment.