Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable cross SDK communication for registering super properties. #651

Merged
merged 1 commit into from
Jul 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading