Skip to content

Commit 62c0a44

Browse files
Notification center (#210)
* Notification center * Listeners added * Send notifications * Test cases * Test case for sendNotifications * refactoring * copyrights changed * redesigned * fixes - after merge * fix - file references * Merge branch 'master' into arafay/notification-center * master: getFeatureVariableValue APIs (#208) # Conflicts: # OptimizelySDKCore/OptimizelySDKCore/Optimizely.m # OptimizelySDKCore/OptimizelySDKCoreTests/OptimizelyTest.m # OptimizelySDKUniversal/OptimizelySDKUniversal.xcodeproj/project.pbxproj * Change request implemented * replaced OPTLYNotificationCenter's logger with OPTLYProjectConfig's logger * replaced Notification's Listeners as callback to delegate * Used NSArray inputs instead of va_list va_start va_end * refactored code comments * removed analyze warning * moved notificationsCount from OPTLYNotificationCenter to OPTLYNotificationCenterTest
1 parent bccb148 commit 62c0a44

File tree

13 files changed

+713
-127
lines changed

13 files changed

+713
-127
lines changed

OptimizelySDKCore/OptimizelySDKCore.xcodeproj/project.pbxproj

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@
102102
3E858C961F42280900D53856 /* OPTLYJSONValueTransformer.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E858C811F4227E300D53856 /* OPTLYJSONValueTransformer.h */; settings = {ATTRIBUTES = (Public, ); }; };
103103
3E858C971F42280900D53856 /* OPTLYJSONValueTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E858C821F4227E300D53856 /* OPTLYJSONValueTransformer.m */; };
104104
3E92800E1F26AD4700214C58 /* BucketerTestsDatafile2.json in Resources */ = {isa = PBXBuildFile; fileRef = 3E92800D1F26AD4700214C58 /* BucketerTestsDatafile2.json */; };
105+
3E95999D20187A2A006E4FD7 /* OPTLYNotificationDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E95999C20187A2A006E4FD7 /* OPTLYNotificationDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
106+
3E95999E20187A2A006E4FD7 /* OPTLYNotificationDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E95999C20187A2A006E4FD7 /* OPTLYNotificationDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
105107
3E99A9F81F4BAF9A009F8805 /* OptimizelySDKCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA2FA81E1DC5DBB100B1D81B /* OptimizelySDKCore.framework */; };
106108
3E99AA001F4BB1BA009F8805 /* ArrayTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E35DC321F47ACFE00018732 /* ArrayTests.m */; };
107109
3E99AA011F4BB1BA009F8805 /* BuiltInConversionsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E35DC331F47ACFE00018732 /* BuiltInConversionsTests.m */; };
@@ -176,6 +178,12 @@
176178
3E9CADFF1FD90E6200EBC49A /* OPTLYFeatureFlag.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E9CADFA1FD90E6200EBC49A /* OPTLYFeatureFlag.m */; };
177179
3E9CAE011FD90E6200EBC49A /* OPTLYFeatureFlag.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E9CADFA1FD90E6200EBC49A /* OPTLYFeatureFlag.m */; };
178180
3EA27B0C1F47AB0D00C0208F /* OptimizelySDKCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA2FA7FE1DC5DBA000B1D81B /* OptimizelySDKCore.framework */; };
181+
3EA563A11FFD23FF00D0E311 /* OPTLYNotificationCenter.m in Sources */ = {isa = PBXBuildFile; fileRef = 3EA5639F1FFD23FE00D0E311 /* OPTLYNotificationCenter.m */; };
182+
3EA563A21FFD23FF00D0E311 /* OPTLYNotificationCenter.m in Sources */ = {isa = PBXBuildFile; fileRef = 3EA5639F1FFD23FE00D0E311 /* OPTLYNotificationCenter.m */; };
183+
3EA563A31FFD23FF00D0E311 /* OPTLYNotificationCenter.h in Headers */ = {isa = PBXBuildFile; fileRef = 3EA563A01FFD23FF00D0E311 /* OPTLYNotificationCenter.h */; settings = {ATTRIBUTES = (Public, ); }; };
184+
3EA563A41FFD23FF00D0E311 /* OPTLYNotificationCenter.h in Headers */ = {isa = PBXBuildFile; fileRef = 3EA563A01FFD23FF00D0E311 /* OPTLYNotificationCenter.h */; settings = {ATTRIBUTES = (Public, ); }; };
185+
3EA818951FFF890D00BEBD41 /* OPTLYNotificationCenterTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 3EA818931FFF88F800BEBD41 /* OPTLYNotificationCenterTest.m */; };
186+
3EA818961FFF890E00BEBD41 /* OPTLYNotificationCenterTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 3EA818931FFF88F800BEBD41 /* OPTLYNotificationCenterTest.m */; };
179187
3ECB81F21FD9267D006505E6 /* OPTLYFeatureVariable.h in Headers */ = {isa = PBXBuildFile; fileRef = 3ECB81F01FD9267D006505E6 /* OPTLYFeatureVariable.h */; settings = {ATTRIBUTES = (Public, ); }; };
180188
3ECB81F31FD9267D006505E6 /* OPTLYFeatureVariable.h in Headers */ = {isa = PBXBuildFile; fileRef = 3ECB81F01FD9267D006505E6 /* OPTLYFeatureVariable.h */; settings = {ATTRIBUTES = (Public, ); }; };
181189
3ECB81F41FD9267D006505E6 /* OPTLYFeatureVariable.m in Sources */ = {isa = PBXBuildFile; fileRef = 3ECB81F11FD9267D006505E6 /* OPTLYFeatureVariable.m */; };
@@ -551,6 +559,7 @@
551559
3E858C811F4227E300D53856 /* OPTLYJSONValueTransformer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OPTLYJSONValueTransformer.h; path = OPTLYJSONModel/OPTLYJSONModel/OPTLYJSONModelTransformations/OPTLYJSONValueTransformer.h; sourceTree = "<group>"; };
552560
3E858C821F4227E300D53856 /* OPTLYJSONValueTransformer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OPTLYJSONValueTransformer.m; path = OPTLYJSONModel/OPTLYJSONModel/OPTLYJSONModelTransformations/OPTLYJSONValueTransformer.m; sourceTree = "<group>"; };
553561
3E92800D1F26AD4700214C58 /* BucketerTestsDatafile2.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = BucketerTestsDatafile2.json; sourceTree = "<group>"; };
562+
3E95999C20187A2A006E4FD7 /* OPTLYNotificationDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OPTLYNotificationDelegate.h; sourceTree = "<group>"; };
554563
3E99A9F31F4BAF9A009F8805 /* OPTLYJSONModelTVOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = OPTLYJSONModelTVOSTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
555564
3E99AA311F4BB1FE009F8805 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS10.2.sdk/System/Library/Frameworks/CoreGraphics.framework; sourceTree = DEVELOPER_DIR; };
556565
3E99AA331F4BB206009F8805 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS10.2.sdk/System/Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; };
@@ -559,6 +568,9 @@
559568
3E9CADFA1FD90E6200EBC49A /* OPTLYFeatureFlag.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OPTLYFeatureFlag.m; sourceTree = "<group>"; };
560569
3EA27B071F47AB0D00C0208F /* OPTLYJSONModeliOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = OPTLYJSONModeliOSTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
561570
3EA27B0B1F47AB0D00C0208F /* OPTLYJSONModelTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "OPTLYJSONModelTests-Info.plist"; sourceTree = "<group>"; };
571+
3EA5639F1FFD23FE00D0E311 /* OPTLYNotificationCenter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OPTLYNotificationCenter.m; sourceTree = "<group>"; };
572+
3EA563A01FFD23FF00D0E311 /* OPTLYNotificationCenter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OPTLYNotificationCenter.h; sourceTree = "<group>"; };
573+
3EA818931FFF88F800BEBD41 /* OPTLYNotificationCenterTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OPTLYNotificationCenterTest.m; sourceTree = "<group>"; };
562574
3ECB81F01FD9267D006505E6 /* OPTLYFeatureVariable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OPTLYFeatureVariable.h; sourceTree = "<group>"; };
563575
3ECB81F11FD9267D006505E6 /* OPTLYFeatureVariable.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OPTLYFeatureVariable.m; sourceTree = "<group>"; };
564576
3ECB81FC1FD926FE006505E6 /* OPTLYVariableUsage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OPTLYVariableUsage.h; sourceTree = "<group>"; };
@@ -925,6 +937,16 @@
925937
name = Implementations;
926938
sourceTree = "<group>";
927939
};
940+
3EA563831FFB621200D0E311 /* Notification */ = {
941+
isa = PBXGroup;
942+
children = (
943+
3EA563A01FFD23FF00D0E311 /* OPTLYNotificationCenter.h */,
944+
3EA5639F1FFD23FE00D0E311 /* OPTLYNotificationCenter.m */,
945+
3E95999C20187A2A006E4FD7 /* OPTLYNotificationDelegate.h */,
946+
);
947+
name = Notification;
948+
sourceTree = "<group>";
949+
};
928950
93BE4E5119FD429B5D9A3435 /* Pods */ = {
929951
isa = PBXGroup;
930952
children = (
@@ -1152,6 +1174,7 @@
11521174
EA87A0271DE3142A002E9EF7 /* UserProfileService */,
11531175
EA2FA8451DC5E1A300B1D81B /* Loggers */,
11541176
EA8FD0C81DE978E400D950AD /* Network */,
1177+
3EA563831FFB621200D0E311 /* Notification */,
11551178
EA2FA83D1DC5E0E900B1D81B /* Utilities */,
11561179
);
11571180
path = OptimizelySDKCore;
@@ -1174,10 +1197,11 @@
11741197
EA8FD0E71DE97DC000D950AD /* OPTLYHTTPRequestManagerTest.m */,
11751198
EA2FAB8F1DC6FDFA00B1D81B /* OPTLYLoggerTest.m */,
11761199
5E4C07FA1DFF66B00042B1F8 /* OPTLYNetworkServiceTest.m */,
1200+
3EA818931FFF88F800BEBD41 /* OPTLYNotificationCenterTest.m */,
11771201
EA2FAB901DC6FDFA00B1D81B /* OPTLYProjectConfigTest.m */,
1202+
EA064BCB1DD3FC9F00DF7537 /* OPTLYQueueTest.m */,
11781203
EA2FAB911DC6FDFA00B1D81B /* OPTLYTestHelper.h */,
11791204
EA2FAB921DC6FDFA00B1D81B /* OPTLYTestHelper.m */,
1180-
EA064BCB1DD3FC9F00DF7537 /* OPTLYQueueTest.m */,
11811205
EA2FAB941DC6FDFA00B1D81B /* TestData */,
11821206
);
11831207
path = OptimizelySDKCoreTests;
@@ -1248,6 +1272,7 @@
12481272
EA8FD0DB1DE9798E00D950AD /* OPTLYHTTPRequestManager.h in Headers */,
12491273
EA2FAB731DC6F5F400B1D81B /* OPTLYLog.h in Headers */,
12501274
EA2FAB521DC6F5BE00B1D81B /* OPTLYLogger.h in Headers */,
1275+
3EA563A31FFD23FF00D0E311 /* OPTLYNotificationCenter.h in Headers */,
12511276
EA2FAB581DC6F5BE00B1D81B /* OPTLYLoggerMessages.h in Headers */,
12521277
EA2FAB0C1DC6F57200B1D81B /* OPTLYProjectConfig.h in Headers */,
12531278
EA2C242D1DE6A2470063ADA0 /* OPTLYProjectConfigBuilder.h in Headers */,
@@ -1270,6 +1295,7 @@
12701295
EA2FAAFA1DC6F57200B1D81B /* OPTLYEventView.h in Headers */,
12711296
EA2FAAD61DC6F57200B1D81B /* OPTLYEventHeader.h in Headers */,
12721297
EA2FAA941DC6F57100B1D81B /* OPTLYBaseCondition.h in Headers */,
1298+
3E95999D20187A2A006E4FD7 /* OPTLYNotificationDelegate.h in Headers */,
12731299
EA2FAAE21DC6F57200B1D81B /* OPTLYEventMetric.h in Headers */,
12741300
EA2FAA8E1DC6F57100B1D81B /* OPTLYAudience.h in Headers */,
12751301
EA2FAA9A1DC6F57100B1D81B /* OPTLYCondition.h in Headers */,
@@ -1308,6 +1334,7 @@
13081334
EA2FAB491DC6F5B100B1D81B /* OPTLYEventBuilder.h in Headers */,
13091335
EA2FAB391DC6F59D00B1D81B /* OPTLYErrorHandlerMessages.h in Headers */,
13101336
EA2FAB741DC6F5F400B1D81B /* OPTLYLog.h in Headers */,
1337+
3EA563A41FFD23FF00D0E311 /* OPTLYNotificationCenter.h in Headers */,
13111338
EA064BC81DD3FC8800DF7537 /* OPTLYQueue.h in Headers */,
13121339
EA2C242E1DE6A2470063ADA0 /* OPTLYProjectConfigBuilder.h in Headers */,
13131340
EA8FD0DC1DE9798E00D950AD /* OPTLYHTTPRequestManager.h in Headers */,
@@ -1330,6 +1357,7 @@
13301357
EA2FAAC51DC6F57200B1D81B /* OPTLYEventDecisionTicket.h in Headers */,
13311358
EA2FAAB31DC6F57200B1D81B /* OPTLYEventAudience.h in Headers */,
13321359
EA2FAAA11DC6F57100B1D81B /* OPTLYDatafileKeys.h in Headers */,
1360+
3E95999E20187A2A006E4FD7 /* OPTLYNotificationDelegate.h in Headers */,
13331361
EA2FAAEF1DC6F57200B1D81B /* OPTLYEventRelatedEvent.h in Headers */,
13341362
EAC5F3441E7B7DDF00C087B8 /* OPTLYEventDispatcherBasic.h in Headers */,
13351363
EA16D9371ECBA9B200C4C998 /* OPTLYUserProfile.h in Headers */,
@@ -1850,6 +1878,7 @@
18501878
EA2FAC0E1DC6FFC600B1D81B /* OPTLYDatafileKeys.m in Sources */,
18511879
EA2FAC0F1DC6FFC600B1D81B /* OPTLYDecisionEventTicket.m in Sources */,
18521880
EA2FAC101DC6FFC600B1D81B /* OPTLYEvent.m in Sources */,
1881+
3EA563A11FFD23FF00D0E311 /* OPTLYNotificationCenter.m in Sources */,
18531882
EA16D9441ECCC5C600C4C998 /* OPTLYDecisionService.m in Sources */,
18541883
EAC5F3551E7B7EEF00C087B8 /* OPTLYUserProfileServiceBasic.m in Sources */,
18551884
EA2FAC111DC6FFC600B1D81B /* OPTLYEventAudience.m in Sources */,
@@ -1901,6 +1930,7 @@
19011930
5E4C07FB1DFF66B00042B1F8 /* OPTLYNetworkServiceTest.m in Sources */,
19021931
EA2FABB41DC6FDFA00B1D81B /* OPTLYEventBuilderTest.m in Sources */,
19031932
EA8FD0EA1DE97DD700D950AD /* OPTLYHTTPRequestManagerTest.m in Sources */,
1933+
3EA818951FFF890D00BEBD41 /* OPTLYNotificationCenterTest.m in Sources */,
19041934
EA2FABB71DC6FDFA00B1D81B /* OPTLYEventDispatcherTest.m in Sources */,
19051935
EA2FABA51DC6FDFA00B1D81B /* OPTLYAudienceTest.m in Sources */,
19061936
EA2FABB11DC6FDFA00B1D81B /* OPTLYErrorHandlerTest.m in Sources */,
@@ -1931,6 +1961,7 @@
19311961
EA2FABEA1DC6FFA100B1D81B /* OPTLYDecisionEventTicket.m in Sources */,
19321962
EA2FABEB1DC6FFA100B1D81B /* OPTLYEvent.m in Sources */,
19331963
EA16D9451ECCC5C600C4C998 /* OPTLYDecisionService.m in Sources */,
1964+
3EA563A21FFD23FF00D0E311 /* OPTLYNotificationCenter.m in Sources */,
19341965
EA2FABEC1DC6FFA100B1D81B /* OPTLYEventAudience.m in Sources */,
19351966
EA2FABED1DC6FFA100B1D81B /* OPTLYEventDecision.m in Sources */,
19361967
EA2FABEE1DC6FFA100B1D81B /* OPTLYEventDecisionTicket.m in Sources */,
@@ -1982,6 +2013,7 @@
19822013
5E4C07FC1DFF66B00042B1F8 /* OPTLYNetworkServiceTest.m in Sources */,
19832014
EA2FABB51DC6FDFA00B1D81B /* OPTLYEventBuilderTest.m in Sources */,
19842015
EA8FD0EB1DE97DD900D950AD /* OPTLYHTTPRequestManagerTest.m in Sources */,
2016+
3EA818961FFF890E00BEBD41 /* OPTLYNotificationCenterTest.m in Sources */,
19852017
EA2FABB81DC6FDFA00B1D81B /* OPTLYEventDispatcherTest.m in Sources */,
19862018
EA2FABA61DC6FDFA00B1D81B /* OPTLYAudienceTest.m in Sources */,
19872019
EA2FABB21DC6FDFA00B1D81B /* OPTLYErrorHandlerTest.m in Sources */,

OptimizelySDKCore/OptimizelySDKCore/OPTLYBuilder.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/****************************************************************************
2-
* Copyright 2016, Optimizely, Inc. and contributors *
2+
* Copyright 2017-2018, Optimizely, Inc. and contributors *
33
* *
44
* Licensed under the Apache License, Version 2.0 (the "License"); *
55
* you may not use this file except in compliance with the License. *
@@ -16,7 +16,7 @@
1616

1717
#import <Foundation/Foundation.h>
1818

19-
@class OPTLYBucketer, OPTLYEventBuilder, OPTLYEventBuilderDefault, OPTLYProjectConfig, OPTLYDecisionService;
19+
@class OPTLYBucketer, OPTLYEventBuilder, OPTLYEventBuilderDefault, OPTLYProjectConfig, OPTLYDecisionService, OPTLYNotificationCenter;
2020
@protocol OPTLYDatafileManager, OPTLYErrorHandler, OPTLYEventBuilder, OPTLYEventDispatcher, OPTLYLogger, OPTLYUserProfileService;
2121

2222
/**
@@ -40,6 +40,8 @@ typedef void (^OPTLYBuilderBlock)(OPTLYBuilder * _Nullable builder);
4040
@property (nonatomic, readonly, strong, nullable) OPTLYDecisionService *decisionService;
4141
/// The event builder created by the builder.
4242
@property (nonatomic, readonly, strong, nullable) OPTLYEventBuilderDefault *eventBuilder;
43+
/// The notification center created by the builder.
44+
@property (nonatomic, readonly, strong, nullable) OPTLYNotificationCenter *notificationCenter;
4345
/// The error handler is by default set to one that is created by Optimizely. This default error handler can be overridden by any object that conforms to the OPTLYErrorHandler protocol.
4446
@property (nonatomic, readwrite, strong, nullable) id<OPTLYErrorHandler> errorHandler;
4547
/// The event dispatcher is by default set to one that is created by Optimizely. This default event dispatcher can be overridden by any object that conforms to the OPTLYEventDispatcher protocol.

OptimizelySDKCore/OptimizelySDKCore/OPTLYBuilder.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/****************************************************************************
2-
* Copyright 2016, Optimizely, Inc. and contributors *
2+
* Copyright 2017-2018, Optimizely, Inc. and contributors *
33
* *
44
* Licensed under the Apache License, Version 2.0 (the "License"); *
55
* you may not use this file except in compliance with the License. *
@@ -22,6 +22,7 @@
2222
#import "OPTLYLogger.h"
2323
#import "OPTLYProjectConfig.h"
2424
#import "OPTLYDecisionService.h"
25+
#import "OPTLYNotificationCenter.h"
2526

2627
@implementation OPTLYBuilder
2728

@@ -74,6 +75,7 @@ - (id)initWithBlock:(OPTLYBuilderBlock)block {
7475
_bucketer = [[OPTLYBucketer alloc] initWithConfig:_config];
7576
_decisionService = [[OPTLYDecisionService alloc] initWithProjectConfig:_config bucketer:_bucketer];
7677
_eventBuilder = [[OPTLYEventBuilderDefault alloc] init];
78+
_notificationCenter = [[OPTLYNotificationCenter alloc] initWithProjectConfig:_config];
7779

7880
return self;
7981
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/****************************************************************************
2+
* Copyright 2018, Optimizely, Inc. and contributors *
3+
* *
4+
* Licensed under the Apache License, Version 2.0 (the "License"); *
5+
* you may not use this file except in compliance with the License. *
6+
* You may obtain a copy of the License at *
7+
* *
8+
* http://www.apache.org/licenses/LICENSE-2.0 *
9+
* *
10+
* Unless required by applicable law or agreed to in writing, software *
11+
* distributed under the License is distributed on an "AS IS" BASIS, *
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13+
* See the License for the specific language governing permissions and *
14+
* limitations under the License. *
15+
***************************************************************************/
16+
17+
#import <Foundation/Foundation.h>
18+
19+
@class OPTLYProjectConfig, OPTLYExperiment, OPTLYVariation;
20+
@protocol OPTLYNotificationDelegate;
21+
22+
/// Enum representing notification types.
23+
typedef NS_ENUM(NSUInteger, OPTLYNotificationType) {
24+
OPTLYNotificationTypeActivate,
25+
OPTLYNotificationTypeTrack
26+
};
27+
28+
typedef NSMutableDictionary<NSNumber *, id<OPTLYNotificationDelegate> > OPTLYNotificationHolder;
29+
30+
@interface OPTLYNotificationCenter : NSObject
31+
32+
// Notification Id represeting id of notification.
33+
@property (nonatomic, readonly) NSUInteger notificationId;
34+
35+
/**
36+
* Initializer for the Notification Center.
37+
*
38+
* @param config The project configuration.
39+
* @return An instance of the notification center.
40+
*/
41+
- (nullable instancetype)initWithProjectConfig:(nonnull OPTLYProjectConfig *)config;
42+
43+
/**
44+
* Add an activate notification listener to the notification center.
45+
*
46+
* @param type - enum OPTLYNotificationType to add.
47+
* @param activateListener - Notification to add.
48+
* @return the notification id used to remove the notification. It is greater than 0 on success.
49+
*/
50+
- (NSInteger)addNotification:(OPTLYNotificationType)type activateListener:(nonnull id<OPTLYNotificationDelegate>)activateListener;
51+
52+
/**
53+
* Add a track notification listener to the notification center.
54+
*
55+
* @param type - enum OPTLYNotificationType to add.
56+
* @param trackListener - Notification to add.
57+
* @return the notification id used to remove the notification. It is greater than 0 on success.
58+
*/
59+
- (NSInteger)addNotification:(OPTLYNotificationType)type trackListener:(nonnull id<OPTLYNotificationDelegate>)trackListener;
60+
61+
/**
62+
* Remove the notification listener based on the notificationId passed back from addNotification.
63+
* @param notificationId the id passed back from add notification.
64+
* @return true if removed otherwise false (if the notification is already removed, it returns false).
65+
*/
66+
- (BOOL)removeNotification:(NSUInteger)notificationId;
67+
68+
/**
69+
* Clear notification listeners by notification type.
70+
* @param type type of OPTLYNotificationType to remove.
71+
*/
72+
- (void)clearNotifications:(OPTLYNotificationType)type;
73+
74+
/**
75+
* Clear out all the notification listeners.
76+
*/
77+
- (void)clearAllNotifications;
78+
79+
//
80+
/**
81+
* fire notificaitons of a certain type.
82+
* @param type type of OPTLYNotificationType to fire.
83+
* @param args The arg list changes depending on the type of notification sent.
84+
*/
85+
- (void)sendNotifications:(OPTLYNotificationType)type args:(nullable NSArray *)args;
86+
@end

0 commit comments

Comments
 (0)