Skip to content

Commit e0c2b81

Browse files
authored
feat: Change embedded view detection (#39)
* feat: Change embedded view detection * Log error for incorrect embedded view type
1 parent 807cb83 commit e0c2b81

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

mParticle-Rokt/MPKitRokt.m

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
NSString * const MPKitRoktErrorMessageKey = @"mParticle-Rokt Error";
88
NSString * const kMPPlacementAttributesMapping = @"placementAttributesMapping";
99
NSString * const kMPHashedEmailUserIdentityType = @"hashedEmailUserIdentityType";
10+
NSString * const kMPRoktEmbeddedViewClassName = @"MPRoktEmbeddedView";
1011
NSInteger const kMPRoktKitCode = 181;
1112

1213
static __weak MPKitRokt *roktKit = nil;
@@ -105,10 +106,11 @@ - (MPKitExecStatus *)executeWithIdentifier:(NSString * _Nullable)identifier
105106

106107
//Convert MPRoktConfig to RoktConfig
107108
RoktConfig *roktConfig = [MPKitRokt convertMPRoktConfig:mpRoktConfig];
109+
NSDictionary<NSString *, RoktEmbeddedView *> *confirmedViews = [self confirmEmbeddedViews:embeddedViews];
108110

109111
[Rokt executeWithViewName:identifier
110112
attributes:finalAtt
111-
placements:[self confirmEmbeddedViews:embeddedViews]
113+
placements:confirmedViews
112114
config:roktConfig
113115
onLoad:callbacks.onLoad
114116
onUnLoad:callbacks.onUnLoad
@@ -145,18 +147,37 @@ - (RoktFrameworkType)mapMPWrapperSdkToRoktFrameworkType:(MPWrapperSdk)wrapperSdk
145147
}
146148

147149
- (NSDictionary<NSString *, RoktEmbeddedView *> * _Nullable) confirmEmbeddedViews:(NSDictionary<NSString *, MPRoktEmbeddedView *> * _Nullable)embeddedViews {
150+
if (!embeddedViews || embeddedViews.count == 0) {
151+
return [NSMutableDictionary dictionary];
152+
}
153+
148154
NSMutableDictionary <NSString *, RoktEmbeddedView *> *safePlacements = [NSMutableDictionary dictionary];
149155

150156
for (NSString* key in embeddedViews) {
151157
MPRoktEmbeddedView *mpView = [embeddedViews objectForKey:key];
152158

153-
if ([mpView isKindOfClass:MPRoktEmbeddedView.class]) {
159+
BOOL isUIView = [mpView isKindOfClass:[UIView class]];
160+
161+
if (!isUIView) {
162+
[MPKitRokt MPLog:[NSString stringWithFormat:@"Rokt embedded view is incorrect type. Found: %@ but required: UIView", NSStringFromClass([mpView class])]];
163+
continue;
164+
}
165+
166+
Class runtimeClass = NSClassFromString(kMPRoktEmbeddedViewClassName);
167+
168+
// Use runtime class for type checking instead of compile-time reference
169+
// This handles cases where the class is defined in multiple frameworks
170+
BOOL isProperType = runtimeClass && [mpView isKindOfClass:runtimeClass];
171+
172+
if (isProperType) {
154173
// Create a new RoktEmbeddedView instance
155174
RoktEmbeddedView *roktView = [[RoktEmbeddedView alloc] initWithFrame:mpView.bounds];
156175
// Add the RoktEmbeddedView as a child view of MPRoktEmbeddedView
157176
[mpView addSubview:roktView];
158177
// Add the RoktEmbeddedView to our safe placements dictionary
159178
[safePlacements setObject:roktView forKey:key];
179+
} else {
180+
[MPKitRokt MPLog:[NSString stringWithFormat:@"Rokt embedded view is incorrect type. Found: %@ but required: %@", NSStringFromClass([mpView class]), kMPRoktEmbeddedViewClassName]];
160181
}
161182
}
162183

0 commit comments

Comments
 (0)