Skip to content

Commit 18536ca

Browse files
authored
Merge pull request #651 from mixpanel/zihe-add-cross-sdks-comm
Enable cross SDK communication for registratering super properties.
2 parents e7869c4 + 5d1e989 commit 18536ca

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Sources/MixpanelInstance.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ open class MixpanelInstance: CustomDebugStringConvertible, FlushDelegate, AEDele
259259
#if os(iOS) || os(tvOS) || os(visionOS)
260260
let automaticEvents = AutomaticEvents()
261261
#endif
262+
private let registerSuperPropertiesNotificationName = Notification.Name("com.mixpanel.properties.register")
263+
private let unregisterSuperPropertiesNotificationName = Notification.Name("com.mixpanel.properties.unregister")
262264

263265
convenience init(
264266
apiToken: String?,
@@ -421,6 +423,18 @@ open class MixpanelInstance: CustomDebugStringConvertible, FlushDelegate, AEDele
421423
selector: #selector(applicationWillEnterForeground(_:)),
422424
name: UIApplication.willEnterForegroundNotification,
423425
object: nil)
426+
notificationCenter.addObserver(
427+
self,
428+
selector: #selector(handleSuperPropertiesRegistrationNotification(_:)),
429+
name: registerSuperPropertiesNotificationName,
430+
object: nil
431+
)
432+
notificationCenter.addObserver(
433+
self,
434+
selector: #selector(handleSuperPropertiesRegistrationNotification(_:)),
435+
name: unregisterSuperPropertiesNotificationName,
436+
object: nil
437+
)
424438
}
425439
}
426440
#elseif os(OSX)
@@ -632,6 +646,20 @@ open class MixpanelInstance: CustomDebugStringConvertible, FlushDelegate, AEDele
632646
#endif
633647
#endif // os(iOS)
634648

649+
@objc func handleSuperPropertiesRegistrationNotification(_ notification: Notification) {
650+
guard let data = notification.userInfo else { return }
651+
652+
if notification.name.rawValue == registerSuperPropertiesNotificationName.rawValue {
653+
guard let properties = data as? Properties else { return }
654+
registerSuperProperties(properties)
655+
} else {
656+
for (key, _) in data {
657+
if let keyToUnregister = key as? String {
658+
unregisterSuperProperty(keyToUnregister)
659+
}
660+
}
661+
}
662+
}
635663
}
636664

637665
extension MixpanelInstance {

0 commit comments

Comments
 (0)