Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions mParticle-Rokt/MPKitRokt.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
NSString * const MPKitRoktErrorMessageKey = @"mParticle-Rokt Error";
NSString * const kMPPlacementAttributesMapping = @"placementAttributesMapping";
NSString * const kMPHashedEmailUserIdentityType = @"hashedEmailUserIdentityType";
NSString * const kMPRoktEmbeddedViewClassName = @"MPRoktEmbeddedView";
NSInteger const kMPRoktKitCode = 181;

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

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

[Rokt executeWithViewName:identifier
attributes:finalAtt
placements:[self confirmEmbeddedViews:embeddedViews]
placements:confirmedViews
config:roktConfig
onLoad:callbacks.onLoad
onUnLoad:callbacks.onUnLoad
Expand Down Expand Up @@ -145,18 +147,37 @@ - (RoktFrameworkType)mapMPWrapperSdkToRoktFrameworkType:(MPWrapperSdk)wrapperSdk
}

- (NSDictionary<NSString *, RoktEmbeddedView *> * _Nullable) confirmEmbeddedViews:(NSDictionary<NSString *, MPRoktEmbeddedView *> * _Nullable)embeddedViews {
if (!embeddedViews || embeddedViews.count == 0) {
return [NSMutableDictionary dictionary];
}

NSMutableDictionary <NSString *, RoktEmbeddedView *> *safePlacements = [NSMutableDictionary dictionary];

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

if ([mpView isKindOfClass:MPRoktEmbeddedView.class]) {
BOOL isUIView = [mpView isKindOfClass:[UIView class]];

if (!isUIView) {
[MPKitRokt MPLog:[NSString stringWithFormat:@"Rokt embedded view is incorrect type. Found: %@ but required: UIView", NSStringFromClass([mpView class])]];
continue;
}
Comment on lines +161 to +164

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need to print a log here as well to notify that the view is of the incorrect type?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great shout I added log for it not being MPRoktEmbeddedView but not for UIView and it'll be helpful for debug!


Class runtimeClass = NSClassFromString(kMPRoktEmbeddedViewClassName);

// Use runtime class for type checking instead of compile-time reference
// This handles cases where the class is defined in multiple frameworks
BOOL isProperType = runtimeClass && [mpView isKindOfClass:runtimeClass];

if (isProperType) {
// Create a new RoktEmbeddedView instance
RoktEmbeddedView *roktView = [[RoktEmbeddedView alloc] initWithFrame:mpView.bounds];
// Add the RoktEmbeddedView as a child view of MPRoktEmbeddedView
[mpView addSubview:roktView];
// Add the RoktEmbeddedView to our safe placements dictionary
[safePlacements setObject:roktView forKey:key];
} else {
[MPKitRokt MPLog:[NSString stringWithFormat:@"Rokt embedded view is incorrect type. Found: %@ but required: %@", NSStringFromClass([mpView class]), kMPRoktEmbeddedViewClassName]];
}
}

Expand Down
Loading