Skip to content

Commit 45235e2

Browse files
committed
Change the conflict configuration case into returning NSError instead of throwing exception
1 parent e997bcb commit 45235e2

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

AdobeBranchExtension/Classes/AdobeBranchExtensionClass.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ FOUNDATION_EXPORT NSString*const ABEBranchEventType;
2323
/// Branch extension event source
2424
FOUNDATION_EXPORT NSString*const ABEBranchEventSource;
2525

26+
/// Branch extension error code
27+
typedef NS_ENUM(NSInteger, ABEBranchErrorCode) {
28+
ABEBranchConflictConfiguration = 2000,
29+
};
30+
2631
/**
2732
This is the class defines the root Adobe / Branch integration for deep linking and events.
2833
*/
@@ -36,9 +41,9 @@ FOUNDATION_EXPORT NSString*const ABEBranchEventSource;
3641

3742
+ (void)configureEventTypes:(nullable NSArray<NSString *> *)eventTypes andEventSources:(nullable NSArray<NSString *> *)eventSources;
3843

39-
+ (void)configureEventExclusionList:(nullable NSArray<NSString *> *)eventNames;
44+
+ (BOOL)configureEventExclusionList:(nullable NSArray<NSString *> *)eventNames error:(NSError * __autoreleasing *)configError;
4045

41-
+ (void)configureEventAllowList:(nullable NSArray<NSString *> *)eventNames;
46+
+ (BOOL)configureEventAllowList:(nullable NSArray<NSString *> *)eventNames error:(NSError * __autoreleasing *)configError;
4247

4348
- (void)handleEvent:(ACPExtensionEvent*)event;
4449

AdobeBranchExtension/Classes/AdobeBranchExtensionClass.m

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
NSString*const ABEBranchEventType = @"com.branch.eventType";
1717
NSString*const ABEBranchEventSource = @"com.branch.eventSource";
1818

19+
// Adobe Launch Branch extension error domain
20+
NSString*const AdobeBranchExtensionErrorDomain = @"io.branch.adobe_launch_extension.error";
21+
1922
// 1. events of this type and source
2023
NSString *const ABEAdobeHubEventType = @"com.adobe.eventType.hub";
2124
NSString *const ABEAdobeSharedStateEventSource = @"com.adobe.eventSource.sharedState";
@@ -93,32 +96,32 @@ + (void)configureEventTypes:(nullable NSArray<NSString *> *)eventTypes andEventS
9396
}
9497
}
9598

96-
+ (void)configureEventExclusionList:(nullable NSArray<NSString *> *)eventNames {
99+
+ (BOOL)configureEventExclusionList:(nullable NSArray<NSString *> *)eventNames error:(NSError * __autoreleasing *)configError {
97100
if (eventNames) {
98101
// If already configured allowList
99102
if ([AdobeBranchExtensionConfig instance].allowList.count != 0) {
100-
@throw [NSException
101-
exceptionWithName:@"ConflictConfiguration"
102-
reason:@"Already configured allowList for AdobeBranchExtensionConfig"
103-
userInfo:nil];
103+
*configError = [NSError errorWithDomain:AdobeBranchExtensionErrorDomain code:ABEBranchConflictConfiguration userInfo:@{NSLocalizedFailureReasonErrorKey: @"Already configured allowList for AdobeBranchExtensionConfig"}];
104+
BNCLogError([NSString stringWithFormat:@"AdobeBranchExtensionConfig error: %@.", *configError]);
105+
return NO;
104106
} else {
105107
[AdobeBranchExtensionConfig instance].exclusionList = eventNames;
106108
}
107109
}
110+
return YES;
108111
}
109112

110-
+ (void)configureEventAllowList:(nullable NSArray<NSString *> *)eventNames {
113+
+ (BOOL)configureEventAllowList:(nullable NSArray<NSString *> *)eventNames error:(NSError * __autoreleasing *)configError {
111114
if (eventNames) {
112115
// If already configured allowList
113116
if ([AdobeBranchExtensionConfig instance].exclusionList.count != 0) {
114-
@throw [NSException
115-
exceptionWithName:@"ConflictConfiguration"
116-
reason:@"Already configured exclusionList for AdobeBranchExtensionConfig"
117-
userInfo:nil];
117+
*configError = [NSError errorWithDomain:AdobeBranchExtensionErrorDomain code:ABEBranchConflictConfiguration userInfo:@{NSLocalizedFailureReasonErrorKey: @"Already configured exclusionList for AdobeBranchExtensionConfig"}];
118+
BNCLogError([NSString stringWithFormat:@"AdobeBranchExtensionConfig error: %@.", *configError]);
119+
return NO;
118120
} else {
119121
[AdobeBranchExtensionConfig instance].allowList = eventNames;
120122
}
121123
}
124+
return YES;
122125
}
123126

124127
- (instancetype)init {

Examples/AdobeBranchExample/AdobeBranchExample/AppDelegate.m

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,17 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
4848

4949
// NOTE! following code will enable you to configure exclusion list or allow list, but you can't define both! If you don't configure any, all events will send to Branch which is not ideal!
5050
// Define the exclusion list of the events names
51-
// [AdobeBranchExtension configureEventExclusionList:@[@"VIEW"]];
51+
// if ([AdobeBranchExtension configureEventExclusionList:@[@"VIEW"] error:&error]) {
52+
// NSLog(@"AdobeBranchExtension AllowList configured");
53+
// } else {
54+
// NSLog(@"%@", error);
55+
// }
5256
// Define the allow list of the events names
53-
[AdobeBranchExtension configureEventAllowList:@[@"VIEW"]];
57+
if ([AdobeBranchExtension configureEventAllowList:@[@"VIEW"] error:&error]) {
58+
NSLog(@"AdobeBranchExtension AllowList configured");
59+
} else {
60+
NSLog(@"%@", error);
61+
}
5462
// register AdobeBranchExtension
5563
if ([ACPCore registerExtension:[AdobeBranchExtension class] error:&error]) {
5664
NSLog(@"AdobeBranchExtension Registered");

0 commit comments

Comments
 (0)