|
7 | 7 | NSString * const MPKitRoktErrorMessageKey = @"mParticle-Rokt Error"; |
8 | 8 | NSString * const kMPPlacementAttributesMapping = @"placementAttributesMapping"; |
9 | 9 | NSString * const kMPHashedEmailUserIdentityType = @"hashedEmailUserIdentityType"; |
| 10 | +NSString * const kMPRoktEmbeddedViewClassName = @"MPRoktEmbeddedView"; |
10 | 11 | NSInteger const kMPRoktKitCode = 181; |
11 | 12 |
|
12 | 13 | static __weak MPKitRokt *roktKit = nil; |
@@ -105,10 +106,11 @@ - (MPKitExecStatus *)executeWithIdentifier:(NSString * _Nullable)identifier |
105 | 106 |
|
106 | 107 | //Convert MPRoktConfig to RoktConfig |
107 | 108 | RoktConfig *roktConfig = [MPKitRokt convertMPRoktConfig:mpRoktConfig]; |
| 109 | + NSDictionary<NSString *, RoktEmbeddedView *> *confirmedViews = [self confirmEmbeddedViews:embeddedViews]; |
108 | 110 |
|
109 | 111 | [Rokt executeWithViewName:identifier |
110 | 112 | attributes:finalAtt |
111 | | - placements:[self confirmEmbeddedViews:embeddedViews] |
| 113 | + placements:confirmedViews |
112 | 114 | config:roktConfig |
113 | 115 | onLoad:callbacks.onLoad |
114 | 116 | onUnLoad:callbacks.onUnLoad |
@@ -145,18 +147,37 @@ - (RoktFrameworkType)mapMPWrapperSdkToRoktFrameworkType:(MPWrapperSdk)wrapperSdk |
145 | 147 | } |
146 | 148 |
|
147 | 149 | - (NSDictionary<NSString *, RoktEmbeddedView *> * _Nullable) confirmEmbeddedViews:(NSDictionary<NSString *, MPRoktEmbeddedView *> * _Nullable)embeddedViews { |
| 150 | + if (!embeddedViews || embeddedViews.count == 0) { |
| 151 | + return [NSMutableDictionary dictionary]; |
| 152 | + } |
| 153 | + |
148 | 154 | NSMutableDictionary <NSString *, RoktEmbeddedView *> *safePlacements = [NSMutableDictionary dictionary]; |
149 | 155 |
|
150 | 156 | for (NSString* key in embeddedViews) { |
151 | 157 | MPRoktEmbeddedView *mpView = [embeddedViews objectForKey:key]; |
152 | 158 |
|
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) { |
154 | 173 | // Create a new RoktEmbeddedView instance |
155 | 174 | RoktEmbeddedView *roktView = [[RoktEmbeddedView alloc] initWithFrame:mpView.bounds]; |
156 | 175 | // Add the RoktEmbeddedView as a child view of MPRoktEmbeddedView |
157 | 176 | [mpView addSubview:roktView]; |
158 | 177 | // Add the RoktEmbeddedView to our safe placements dictionary |
159 | 178 | [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]]; |
160 | 181 | } |
161 | 182 | } |
162 | 183 |
|
|
0 commit comments