Skip to content
Draft
Show file tree
Hide file tree
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
35 changes: 12 additions & 23 deletions Example/mParticleExample/ViewController.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import "ViewController.h"
#import <mParticle_Apple_SDK/mParticle.h>
@import RoktContracts;
#import <mParticle_Apple_Media_SDK-Swift.h>
#import <AdSupport/AdSupport.h>
#import "AdSupport/ASIdentifierManager.h"
Expand All @@ -16,7 +17,7 @@ @interface ViewController () <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UITextField *emailField;
@property (nonatomic, strong) UITextField *customerIDField;
@property (nonatomic, strong) MPRoktEmbeddedView *roktView;
@property (nonatomic, strong) RoktEmbeddedView *roktView;

@end

Expand Down Expand Up @@ -58,7 +59,7 @@ - (void)setupUI:(CGFloat)roktHeight {
if (self.roktView) {
self.roktView.frame = roktFrame;
} else {
self.roktView = [[MPRoktEmbeddedView alloc] initWithFrame:roktFrame];
self.roktView = [[RoktEmbeddedView alloc] initWithFrame:roktFrame];
}
[self.view addSubview:_roktView];

Expand Down Expand Up @@ -254,13 +255,13 @@ - (void)selectDarkOverlayPlacement {
@"mobile": @"(555)867-5309"
};

MPRoktConfig *roktConfig = [[MPRoktConfig alloc] init];
roktConfig.colorMode = MPColorModeDark;
RoktConfig *roktConfig = [[RoktConfig alloc] init];
roktConfig.colorMode = RoktColorModeDark;
[[MParticle sharedInstance].rokt selectPlacements:@"RoktLayout"
attributes:customAttributes
embeddedViews:nil
config:roktConfig
callbacks:nil];
onEvent:nil];
}

- (void)selectEmbeddedPlacement {
Expand All @@ -272,26 +273,14 @@ - (void)selectEmbeddedPlacement {
@"mobile": @"(555)867-5309"
};

MPRoktEventCallback *callbacks = [[MPRoktEventCallback alloc] init];
callbacks.onLoad = ^{
// Optional callback for when the Rokt placement loads
};
callbacks.onUnLoad = ^{
// Optional callback for when the Rokt placement unloads
};
callbacks.onShouldShowLoadingIndicator = ^{
// Optional callback to show a loading indicator
};
callbacks.onShouldHideLoadingIndicator = ^{
// Optional callback to hide a loading indicator
};
callbacks.onEmbeddedSizeChange = ^(NSString *placement, CGFloat size) {
[self setupUI:size];
};

NSDictionary *embeddedViews = @{@"Location1": self.roktView};

[[MParticle sharedInstance].rokt selectPlacements:@"testiOS" attributes:customAttributes embeddedViews:embeddedViews config:nil callbacks:callbacks];
[[MParticle sharedInstance].rokt selectPlacements:@"testiOS"
attributes:customAttributes
embeddedViews:embeddedViews
config:nil
onEvent:^(__unused RoktEvent * _Nonnull event) {
}];
}

- (void)selectOverlayPlacementAutoClose {
Expand Down
23 changes: 12 additions & 11 deletions Kits/rokt/rokt/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ let package = Package(
)
],
dependencies: [
.package(path: "../../../"),
.package(path: "../../../../Rokt/rokt-sdk-ios"),
.package(
url: "https://github.com/mParticle/mparticle-apple-sdk",
branch: "workstation/9.0-Release"
),
.package(
url: "https://github.com/ROKT/rokt-sdk-ios",
.upToNextMajor(from: "4.16.1")
url: "https://github.com/ROKT/rokt-contracts-apple.git",
branch: "main"
),
.package(
url: "https://github.com/erikdoe/ocmock",
Expand All @@ -29,8 +27,9 @@ let package = Package(
.target(
name: "mParticle-Rokt",
dependencies: [
.product(name: "mParticle-Apple-SDK", package: "mParticle-Apple-SDK"),
.product(name: "Rokt-Widget", package: "rokt-sdk-ios")
.product(name: "mParticle-Apple-SDK", package: "mparticle-apple-sdk"),
.product(name: "Rokt-Widget", package: "rokt-sdk-ios"),
.product(name: "RoktContracts", package: "rokt-contracts-apple")
],
path: "Sources/mParticle-Rokt",
resources: [.process("PrivacyInfo.xcprivacy")],
Expand All @@ -40,8 +39,9 @@ let package = Package(
name: "mParticle-Rokt-Swift",
dependencies: [
"mParticle-Rokt",
.product(name: "mParticle-Apple-SDK", package: "mParticle-Apple-SDK"),
.product(name: "Rokt-Widget", package: "rokt-sdk-ios")
.product(name: "mParticle-Apple-SDK", package: "mparticle-apple-sdk"),
.product(name: "Rokt-Widget", package: "rokt-sdk-ios"),
.product(name: "RoktContracts", package: "rokt-contracts-apple")
],
path: "Sources/mParticle-Rokt-Swift"
),
Expand All @@ -56,7 +56,8 @@ let package = Package(
name: "mParticle-RoktSwiftTests",
dependencies: [
"mParticle-Rokt",
"mParticle-Rokt-Swift"
"mParticle-Rokt-Swift",
.product(name: "RoktContracts", package: "rokt-contracts-apple")
]
)
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import Foundation
import ObjectiveC
import mParticle_Apple_SDK
import RoktContracts

extension MPRokt {
public func subscribeToPlacementEvents(
_ identifier: String,
onEvent: @escaping (RoktEvent) -> Void
) {
typealias Block = @convention(block) (RoktEvent) -> Void
let sel = NSSelectorFromString("events:onEvent:")
guard let method = class_getInstanceMethod(MPRokt.self, sel) else { return }
let imp = method_getImplementation(method)
typealias Fn = @convention(c) (AnyObject, Selector, NSString, Block?) -> Void
unsafeBitCast(imp, to: Fn.self)(self, sel, identifier as NSString, onEvent as Block)
}

public func subscribeToGlobalEvents(_ onEvent: @escaping (RoktEvent) -> Void) {
typealias Block = @convention(block) (RoktEvent) -> Void
let sel = NSSelectorFromString("globalEvents:")
guard let method = class_getInstanceMethod(MPRokt.self, sel) else { return }
let imp = method_getImplementation(method)
typealias Fn = @convention(c) (AnyObject, Selector, Block) -> Void
unsafeBitCast(imp, to: Fn.self)(self, sel, onEvent as Block)
}

public func selectPlacements(
_ identifier: String,
attributes: [String: String],
embeddedViews: [String: RoktEmbeddedView]?,
config: RoktConfig?,
onEvent: ((RoktEvent) -> Void)?
) {
typealias EventBlock = @convention(block) (RoktEvent) -> Void
let sel = NSSelectorFromString("selectPlacements:attributes:embeddedViews:config:onEvent:")
guard let method = class_getInstanceMethod(MPRokt.self, sel) else { return }
let imp = method_getImplementation(method)
typealias Fn = @convention(c) (
AnyObject,
Selector,
NSString,
NSDictionary?,
NSDictionary?,
RoktConfig?,
EventBlock?
) -> Void
let attrs = attributes as NSDictionary
let embedded = embeddedViews as NSDictionary?
let block: EventBlock? = onEvent.map { cb in cb as EventBlock }
unsafeBitCast(imp, to: Fn.self)(self, sel, identifier as NSString, attrs, embedded, config, block)
}
}
12 changes: 6 additions & 6 deletions Kits/rokt/rokt/Sources/mParticle-Rokt-Swift/MPRoktLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import SwiftUI
import Rokt_Widget
import RoktContracts
import mParticle_Apple_SDK
import mParticle_Rokt

Expand All @@ -23,16 +24,15 @@ public class MPRoktLayout {

public init(
sdkTriggered: Binding<Bool>,
viewName: String? = nil,
viewName: String = "",
locationName: String = "",
attributes: [String: String],
config: RoktConfig? = nil,
onEvent: ((RoktEvent) -> Void)? = nil
) {
// Capture the timestamp when the SwiftUI component is rendered
let options = PlacementOptions(
jointSdkSelectPlacements: Int64(Date().timeIntervalSince1970 * 1000),
dynamicPerformanceMarkers: [:]
let options = RoktPlacementOptions(
timestamp: Int64(Date().timeIntervalSince1970 * 1000)
)

MPRoktLayout
Expand Down Expand Up @@ -63,8 +63,8 @@ public class MPRoktLayout {
)
self.roktLayout = RoktLayout.init(
sdkTriggered: sdkTriggered,
viewName: viewName,
locationName: locationName,
identifier: viewName,
location: locationName,
attributes: preparedAttributes,
config: config,
placementOptions: options,
Expand Down
Loading