@@ -42,7 +42,7 @@ open class OptimizelyManager: NSObject {
42
42
public var notificationCenter : OPTNotificationCenter {
43
43
return HandlerRegistryService . shared. injectNotificationCenter ( sdkKey: self . sdkKey) !
44
44
}
45
-
45
+
46
46
private let reInitLock = Dispatch . DispatchSemaphore ( value: 1 )
47
47
48
48
// MARK: - Public interfaces
@@ -671,10 +671,8 @@ open class OptimizelyManager: NSObject {
671
671
672
672
}
673
673
674
- // MARK: - ObjC APIs
675
-
676
674
extension OptimizelyManager {
677
-
675
+ @ available ( swift , obsoleted : 1.0 )
678
676
@objc public convenience init ( sdkKey: String ) {
679
677
self . init ( sdkKey: sdkKey,
680
678
logger: nil ,
@@ -696,6 +694,7 @@ extension OptimizelyManager {
696
694
697
695
}
698
696
697
+ @available ( swift, obsoleted: 1.0 )
699
698
@objc ( initializeSDKWithCompletion: )
700
699
public func _objcInitializeSDK( completion: ( ( Data ? , NSError ? ) -> Void ) ? ) {
701
700
initializeSDK { result in
@@ -707,24 +706,110 @@ extension OptimizelyManager {
707
706
}
708
707
}
709
708
}
709
+
710
+ @available ( swift, obsoleted: 1.0 )
711
+ @objc ( notificationCenter) public var objc_notificationCenter : _ObjcOPTNotificationCenter {
712
+ class ObjcCenter : _ObjcOPTNotificationCenter {
713
+ var notifications : OPTNotificationCenter
714
+
715
+ init ( notificationCenter: OPTNotificationCenter ) {
716
+ notifications = notificationCenter
717
+ }
718
+
719
+ internal func convertAttribues( attributes: OptimizelyAttributes ? ) -> [ String : Any ] ? {
720
+ return attributes? . mapValues ( { ( val) -> Any in
721
+ if let val = val {
722
+ return val
723
+ }
724
+ else {
725
+ return NSNull ( )
726
+ }
727
+ } )
728
+ }
729
+
730
+ internal func returnVal( num: Int ? ) -> NSNumber ? {
731
+ if let num = num {
732
+ return NSNumber ( value: num)
733
+ }
734
+
735
+ return nil
736
+ }
737
+
738
+ func addActivateNotificationListener( activateListener: @escaping ( [ String : Any ] , String , [ String : Any ] ? , [ String : Any ] , Dictionary < String , Any > ) -> Void ) -> NSNumber ? {
739
+
740
+ let num = notifications. addActivateNotificationListener { ( experiment, userId, attributes, variation, event) in
741
+
742
+ activateListener ( experiment, userId, self . convertAttribues ( attributes: attributes) , variation, event)
743
+ }
744
+
745
+ return returnVal ( num: num)
746
+ }
747
+
748
+ func addTrackNotificationListener( trackListener: @escaping ( String , String , [ String : Any ] ? , Dictionary < String , Any > ? , Dictionary < String , Any > ) -> Void ) -> NSNumber ? {
749
+ let num = notifications. addTrackNotificationListener { ( eventKey, userId, attributes, eventTags, event) in
750
+
751
+ trackListener ( eventKey, userId, self . convertAttribues ( attributes: attributes) , eventTags, event)
752
+ }
753
+
754
+ return returnVal ( num: num)
755
+ }
756
+
757
+ func addDecisionNotificationListener( decisionListener: @escaping ( String , String , [ String : Any ] ? , Dictionary < String , Any > ) -> Void ) -> NSNumber ? {
758
+
759
+ let num = notifications. addDecisionNotificationListener { ( type, userId, attributes, decisionInfo) in
760
+ decisionListener ( type, userId, self . convertAttribues ( attributes: attributes) , decisionInfo)
761
+ }
762
+ return returnVal ( num: num)
763
+ }
764
+
765
+ func addDatafileChangeNotificationListener( datafileListener: @escaping ( Data ) -> Void ) -> NSNumber ? {
766
+ let num = notifications. addDatafileChangeNotificationListener { ( data) in
767
+ datafileListener ( data)
768
+ }
769
+
770
+ return returnVal ( num: num)
771
+ }
772
+
773
+ func removeNotificationListener( notificationId: Int ) {
774
+ notifications. removeNotificationListener ( notificationId: notificationId)
775
+ }
776
+
777
+ func clearNotificationListeners( type: NotificationType ) {
778
+ notifications. clearNotificationListeners ( type: type)
779
+ }
780
+
781
+ func clearAllNotificationListeners( ) {
782
+ notifications. clearAllNotificationListeners ( )
783
+ }
784
+
785
+
786
+ }
787
+
788
+ return ObjcCenter ( notificationCenter: self . notificationCenter)
789
+ }
710
790
791
+
792
+ @available ( swift, obsoleted: 1.0 )
711
793
@objc ( initializeSDKWithDatafile: error: )
712
794
public func _objcInitializeSDKWith( datafile: String ) throws {
713
795
try self . initializeSDK ( datafile: datafile)
714
796
}
715
797
798
+ @available ( swift, obsoleted: 1.0 )
716
799
@objc ( initializeSDKWithDatafile: doFetchDatafileBackground: error: )
717
800
public func _objcInitializeSDK( datafile: Data , doFetchDatafileBackground: Bool = true ) throws {
718
801
try self . initializeSDK ( datafile: datafile, doFetchDatafileBackground: doFetchDatafileBackground)
719
802
}
720
803
804
+ @available ( swift, obsoleted: 1.0 )
721
805
@objc ( activateWithExperimentKey: userId: attributes: error: )
722
806
public func _objcActivate( experimentKey: String ,
723
807
userId: String ,
724
808
attributes: [ String : Any ] ? ) throws -> String {
725
809
return try self . activate ( experimentKey: experimentKey, userId: userId, attributes: attributes as OptimizelyAttributes ? )
726
810
}
727
811
812
+ @available ( swift, obsoleted: 1.0 )
728
813
@objc ( getVariationKeyWithExperimentKey: userId: attributes: error: )
729
814
public func _objcGetVariationKey( experimentKey: String ,
730
815
userId: String ,
@@ -734,12 +819,14 @@ extension OptimizelyManager {
734
819
attributes: attributes)
735
820
}
736
821
822
+ @available ( swift, obsoleted: 1.0 )
737
823
@objc ( getForcedVariationWithExperimentKey: userId: )
738
824
public func _objcGetForcedVariation( experimentKey: String , userId: String ) -> String ? {
739
825
return getForcedVariation ( experimentKey: experimentKey,
740
826
userId: userId)
741
827
}
742
828
829
+ @available ( swift, obsoleted: 1.0 )
743
830
@objc ( setForcedVariationWithExperimentKey: userId: variationKey: )
744
831
public func _objcSetForcedVariation( experimentKey: String ,
745
832
userId: String ,
@@ -749,6 +836,7 @@ extension OptimizelyManager {
749
836
variationKey: variationKey)
750
837
}
751
838
839
+ @available ( swift, obsoleted: 1.0 )
752
840
@objc ( isFeatureEnabledWithFeatureKey: userId: attributes: error: )
753
841
public func _objcIsFeatureEnabled( featureKey: String ,
754
842
userId: String ,
@@ -759,6 +847,8 @@ extension OptimizelyManager {
759
847
return NSNumber ( booleanLiteral: enabled)
760
848
}
761
849
850
+
851
+ @available ( swift, obsoleted: 1.0 )
762
852
@objc ( getFeatureVariableBooleanWithFeatureKey: variableKey: userId: attributes: error: )
763
853
public func _objcGetFeatureVariableBoolean( featureKey: String ,
764
854
variableKey: String ,
@@ -771,6 +861,7 @@ extension OptimizelyManager {
771
861
return NSNumber ( booleanLiteral: value)
772
862
}
773
863
864
+ @available ( swift, obsoleted: 1.0 )
774
865
@objc ( getFeatureVariableDoubleWithFeatureKey: variableKey: userId: attributes: error: )
775
866
public func _objcGetFeatureVariableDouble( featureKey: String ,
776
867
variableKey: String ,
@@ -783,6 +874,7 @@ extension OptimizelyManager {
783
874
return NSNumber ( value: value)
784
875
}
785
876
877
+ @available ( swift, obsoleted: 1.0 )
786
878
@objc ( getFeatureVariableIntegerWithFeatureKey: variableKey: userId: attributes: error: )
787
879
public func _objcGetFeatureVariableInteger( featureKey: String ,
788
880
variableKey: String ,
@@ -795,6 +887,7 @@ extension OptimizelyManager {
795
887
return NSNumber ( integerLiteral: value)
796
888
}
797
889
890
+ @available ( swift, obsoleted: 1.0 )
798
891
@objc ( getFeatureVariableStringWithFeatureKey: variableKey: userId: attributes: error: )
799
892
public func _objcGetFeatureVariableString( featureKey: String ,
800
893
variableKey: String ,
@@ -806,12 +899,14 @@ extension OptimizelyManager {
806
899
attributes: attributes)
807
900
}
808
901
902
+ @available ( swift, obsoleted: 1.0 )
809
903
@objc ( getEnabledFeaturesWithUserId: attributes: error: )
810
904
public func _objcGetEnabledFeatures( userId: String ,
811
905
attributes: [ String : Any ] ? ) throws -> [ String ] {
812
906
return try self . getEnabledFeatures ( userId: userId, attributes: attributes)
813
907
}
814
908
909
+ @available ( swift, obsoleted: 1.0 )
815
910
@objc ( trackWithEventKey: userId: attributes: eventTags: error: )
816
911
public func _objcTrack( eventKey: String ,
817
912
userId: String ,
@@ -881,7 +976,6 @@ extension OptimizelyManager {
881
976
}
882
977
883
978
// MARK: - ObjC protocols
884
-
885
979
@objc ( OPTEventDispatcher) public protocol _ObjcOPTEventDispatcher {
886
980
func dispatchEvent( event: EventForDispatch , completionHandler: ( ( Data ? , NSError ? ) -> Void ) ? )
887
981
0 commit comments