@adjoe/react-native-adjoe-sdk 0.0.0-stage → 5.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -2
- package/android/build.gradle +93 -0
- package/android/src/main/AndroidManifest.xml +11 -0
- package/android/src/main/java/io/adjoe/sdk/reactnative/BasicUtil.kt +361 -0
- package/android/src/main/java/io/adjoe/sdk/reactnative/ErrorsUtil.kt +113 -0
- package/android/src/main/java/io/adjoe/sdk/reactnative/PlaytimeProtectionImpl.kt +150 -0
- package/android/src/main/java/io/adjoe/sdk/reactnative/PlaytimeStudioImpl.kt +313 -0
- package/android/src/main/java/io/adjoe/sdk/reactnative/RNPlaytimeSdkImpl.kt +173 -0
- package/android/src/main/java/io/adjoe/sdk/reactnative/RNPlaytimeSdkPackage.kt +55 -0
- package/android/src/main/java/io/adjoe/sdk/reactnative/StudioUtil.kt +421 -0
- package/android/src/main/java/io/adjoe/sdk/reactnative/Util.kt +40 -0
- package/android/src/newarch/java/io/adjoe/sdk/reactnative/RNPlaytimeProtection.kt +25 -0
- package/android/src/newarch/java/io/adjoe/sdk/reactnative/RNPlaytimeSdkModule.kt +57 -0
- package/android/src/newarch/java/io/adjoe/sdk/reactnative/RNPlaytimeStudio.kt +66 -0
- package/android/src/oldarch/java/io/adjoe/sdk/reactnative/RNPlaytimeProtection.kt +29 -0
- package/android/src/oldarch/java/io/adjoe/sdk/reactnative/RNPlaytimeSdkModule.kt +68 -0
- package/android/src/oldarch/java/io/adjoe/sdk/reactnative/RNPlaytimeStudio.kt +83 -0
- package/ios/AdjoeSdk.xcodeproj/project.pbxproj +281 -0
- package/ios/AdjoeSdk.xcodeproj/xcuserdata/hamid.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
- package/ios/AdjoeSdk.xcworkspace/contents.xcworkspacedata +7 -0
- package/ios/ErrorsUtil.swift +180 -0
- package/ios/PlaytimeProtectionImpl.swift +20 -0
- package/ios/PlaytimeSdkImpl.swift +173 -0
- package/ios/PlaytimeStudioImpl.swift +272 -0
- package/ios/RNPlaytimeBasic.mm +187 -0
- package/ios/RNPlaytimeHelpers.h +21 -0
- package/ios/RNPlaytimeHelpers.m +94 -0
- package/ios/RNPlaytimeProtection.mm +77 -0
- package/ios/RNPlaytimeStudio.mm +265 -0
- package/package.json +35 -4
- package/react-native-adjoe-sdk.podspec +30 -0
- package/src/Playtime.js +158 -0
- package/src/PlaytimeException.js +140 -0
- package/src/PlaytimeProtection.js +40 -0
- package/src/PlaytimeStudio.js +110 -0
- package/src/index.js +8 -0
- package/src/specs/NativePlaytimeProtection.ts +9 -0
- package/src/specs/NativePlaytimeStudio.ts +23 -0
- package/src/specs/NativeRNPlaytimeSdk.ts +17 -0
- package/src-ts/Playtime.d.ts +407 -0
- package/src-ts/PlaytimeException.d.ts +87 -0
- package/src-ts/PlaytimeProtection.d.ts +106 -0
- package/src-ts/PlaytimeStudio.d.ts +818 -0
- package/src-ts/index.d.ts +8 -0
- package/tsconfig.json +114 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import React
|
|
3
|
+
import PlaytimeSDK
|
|
4
|
+
|
|
5
|
+
@objc public class PlaytimeSdkImpl: NSObject {
|
|
6
|
+
|
|
7
|
+
/// Keeps the registered listener alive while the SDK holds it weakly.
|
|
8
|
+
private var eventListener: AnyObject?
|
|
9
|
+
|
|
10
|
+
/// Set by the Objective-C module to forward Playtime SDK events to the bridge's event
|
|
11
|
+
/// emitter as a device event. A publisher's JS listener object cannot cross the bridge,
|
|
12
|
+
/// so delivery goes through this closure instead.
|
|
13
|
+
@objc public var onEvent: ((NSDictionary) -> Void)?
|
|
14
|
+
|
|
15
|
+
fileprivate static let isoFormatter: ISO8601DateFormatter = {
|
|
16
|
+
let formatter = ISO8601DateFormatter()
|
|
17
|
+
formatter.formatOptions = [.withInternetDateTime]
|
|
18
|
+
return formatter
|
|
19
|
+
}()
|
|
20
|
+
|
|
21
|
+
/// Initialize the Playtime SDK with the given options.
|
|
22
|
+
@objc public func initPlaytime(_ options: NSDictionary,
|
|
23
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
24
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
25
|
+
Task {
|
|
26
|
+
let initOptions: InitOptions
|
|
27
|
+
do {
|
|
28
|
+
initOptions = try RNPlaytimeHelpers.initOptions(from: options as! [AnyHashable: Any])
|
|
29
|
+
} catch {
|
|
30
|
+
ErrorsUtil.reject(reject, context: "Invalid parameters for initPlaytime", error)
|
|
31
|
+
return
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
do {
|
|
35
|
+
try await Playtime.initPlaytime(options: initOptions)
|
|
36
|
+
resolve(nil)
|
|
37
|
+
} catch {
|
|
38
|
+
ErrorsUtil.reject(reject, context: "Error initializing SDK", error)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/// Present a screen view with the Playtime catalog.
|
|
44
|
+
/// - Parameters:
|
|
45
|
+
/// - catalogOptions: Options for the catalog request.
|
|
46
|
+
@objc public func showCatalog(_ options: NSDictionary,
|
|
47
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
48
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
49
|
+
Task {
|
|
50
|
+
let catalogOptions: CatalogOptions
|
|
51
|
+
do {
|
|
52
|
+
catalogOptions = try CatalogOptions(JSONObject: options as! [AnyHashable: Any])
|
|
53
|
+
} catch {
|
|
54
|
+
ErrorsUtil.reject(reject, context: "Invalid parameters for showCatalog", error)
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
do {
|
|
59
|
+
try await Playtime.showCatalog(catalogOptions: catalogOptions)
|
|
60
|
+
resolve(nil)
|
|
61
|
+
} catch {
|
|
62
|
+
ErrorsUtil.reject(reject, context: "Playtime catalog error", error)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/// Get the status of the SDK.
|
|
68
|
+
@objc public func getStatus(_ resolve: @escaping RCTPromiseResolveBlock,
|
|
69
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
70
|
+
Task {
|
|
71
|
+
do {
|
|
72
|
+
let response = try await Playtime.getStatus()
|
|
73
|
+
resolve(response.toJSONObject())
|
|
74
|
+
} catch {
|
|
75
|
+
ErrorsUtil.reject(reject, context: "Error getting status", error)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/// Deinitialize the SDK. This releases the resources taken up by internal components.
|
|
81
|
+
@objc public func teardown(_ resolve: @escaping RCTPromiseResolveBlock,
|
|
82
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
83
|
+
Task {
|
|
84
|
+
do {
|
|
85
|
+
try await Playtime.teardown()
|
|
86
|
+
resolve(nil)
|
|
87
|
+
} catch {
|
|
88
|
+
ErrorsUtil.reject(reject, context: "Error deinitializing SDK", error)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/// Records that a catalog entry point became visible. This mandatory event is used for analytics to understand conversion rates from catalog visibility to catalog opens. Pass the placement for the entry point that is visible; use different placements when the app has multiple catalog entry points.
|
|
94
|
+
/// - Parameters:
|
|
95
|
+
/// - catalogPlacement: The placement for the visible catalog entry point.
|
|
96
|
+
@objc public func executeImpressionEvent(_ catalogPlacement: NSDictionary,
|
|
97
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
98
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
99
|
+
Task {
|
|
100
|
+
let placement: CatalogPlacement
|
|
101
|
+
do {
|
|
102
|
+
placement = try CatalogPlacement(JSONObject: catalogPlacement as! [AnyHashable: Any])
|
|
103
|
+
} catch {
|
|
104
|
+
ErrorsUtil.reject(reject, context: "Invalid parameters for executeImpressionEvent", error)
|
|
105
|
+
return
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
do {
|
|
109
|
+
try await Playtime.executeImpressionEvent(catalogPlacement: placement)
|
|
110
|
+
resolve(nil)
|
|
111
|
+
} catch {
|
|
112
|
+
ErrorsUtil.reject(reject, context: "Error executing impression event", error)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/// Register a listener to receive Playtime SDK events.
|
|
118
|
+
///
|
|
119
|
+
/// A publisher's JS listener object cannot cross the bridge, so events are delivered as
|
|
120
|
+
/// device events instead: the registered proxy forwards each event to `onEvent`, which the
|
|
121
|
+
/// Objective-C module wires to the bridge's event emitter. The JS NativeEventEmitter then
|
|
122
|
+
/// relays it to the publisher's `didReceive` callback.
|
|
123
|
+
@objc public func addEventListener(_ resolve: @escaping RCTPromiseResolveBlock,
|
|
124
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
125
|
+
Task { @MainActor in
|
|
126
|
+
let listener = PlaytimeEventListenerProxy { [weak self] payload in
|
|
127
|
+
self?.onEvent?(payload)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
do {
|
|
131
|
+
try await Playtime.addEventListener(eventListener: listener)
|
|
132
|
+
self.eventListener = listener
|
|
133
|
+
resolve(nil)
|
|
134
|
+
} catch {
|
|
135
|
+
self.eventListener = nil
|
|
136
|
+
ErrorsUtil.reject(reject, context: "Error adding event listener", error)
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/// Remove the currently registered Playtime SDK event listener.
|
|
142
|
+
@objc public func removeEventListener(_ resolve: @escaping RCTPromiseResolveBlock,
|
|
143
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
144
|
+
Task {
|
|
145
|
+
do {
|
|
146
|
+
try await Playtime.removeEventListener()
|
|
147
|
+
self.eventListener = nil
|
|
148
|
+
resolve(nil)
|
|
149
|
+
} catch {
|
|
150
|
+
ErrorsUtil.reject(reject, context: "Error removing event listener", error)
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
@MainActor
|
|
157
|
+
private final class PlaytimeEventListenerProxy: NSObject, PlaytimeEventListener {
|
|
158
|
+
|
|
159
|
+
private let handler: (NSDictionary) -> Void
|
|
160
|
+
|
|
161
|
+
init(handler: @escaping (NSDictionary) -> Void) {
|
|
162
|
+
self.handler = handler
|
|
163
|
+
super.init()
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
func didReceive(_ event: PlaytimeEvent) {
|
|
167
|
+
let payload: NSDictionary = [
|
|
168
|
+
"name": event.name,
|
|
169
|
+
"occurredAt": PlaytimeSdkImpl.isoFormatter.string(from: event.occurredAt)
|
|
170
|
+
]
|
|
171
|
+
handler(payload)
|
|
172
|
+
}
|
|
173
|
+
}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import React
|
|
3
|
+
import PlaytimeSDK
|
|
4
|
+
|
|
5
|
+
@objc public class PlaytimeStudioImpl: NSObject {
|
|
6
|
+
|
|
7
|
+
@objc public func updateTosConsent(_ action: Double,
|
|
8
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
9
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
10
|
+
Task {
|
|
11
|
+
let consentAction: TosConsentAction = (Int(action) == 1) ? .withdraw : .accept
|
|
12
|
+
|
|
13
|
+
do {
|
|
14
|
+
try await PlaytimeStudio.updateTosConsent(action: consentAction)
|
|
15
|
+
resolve(nil)
|
|
16
|
+
} catch {
|
|
17
|
+
ErrorsUtil.reject(reject, context: "Error updating terms of service consent", error)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@objc public func getCampaigns(_ options: NSDictionary,
|
|
23
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
24
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
25
|
+
Task {
|
|
26
|
+
let campaignOptions: CampaignOptions
|
|
27
|
+
|
|
28
|
+
do {
|
|
29
|
+
campaignOptions = try CampaignOptions(JSONObject: options as! [AnyHashable: Any])
|
|
30
|
+
} catch {
|
|
31
|
+
ErrorsUtil.reject(reject, context: "Invalid parameters for getCampaigns", error)
|
|
32
|
+
return
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
do {
|
|
36
|
+
let response = try await PlaytimeStudio.getCampaigns(campaignOptions: campaignOptions)
|
|
37
|
+
resolve(response.toJSONObject())
|
|
38
|
+
} catch {
|
|
39
|
+
ErrorsUtil.reject(reject, context: "Error getting campaigns", error)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@objc public func getOfferDetails(_ tokens: [String],
|
|
45
|
+
campaignOptions options: NSDictionary,
|
|
46
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
47
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
48
|
+
Task {
|
|
49
|
+
let campaignOptions: CampaignOptions
|
|
50
|
+
|
|
51
|
+
do {
|
|
52
|
+
campaignOptions = try CampaignOptions(JSONObject: options as! [AnyHashable: Any])
|
|
53
|
+
} catch {
|
|
54
|
+
ErrorsUtil.reject(reject, context: "Invalid parameters for getOfferDetails", error)
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if tokens.isEmpty {
|
|
59
|
+
ErrorsUtil.reject(reject, function: "getOfferDetails", reason: "tokens array is required")
|
|
60
|
+
return
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
do {
|
|
64
|
+
let response = try await PlaytimeStudio.getOfferDetails(tokens: tokens, campaignOptions: campaignOptions)
|
|
65
|
+
resolve(response.toJSONObject())
|
|
66
|
+
} catch {
|
|
67
|
+
ErrorsUtil.reject(reject, context: "Error getting offer details", error)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@objc public func getInstalledCampaigns(_ options: NSDictionary,
|
|
73
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
74
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
75
|
+
Task {
|
|
76
|
+
do {
|
|
77
|
+
let installedOptions = try InstalledCampaignOptions(JSONObject: options as! [AnyHashable: Any])
|
|
78
|
+
let response = try await PlaytimeStudio.getInstalledCampaigns(options: installedOptions)
|
|
79
|
+
resolve(response.toJSONObject())
|
|
80
|
+
} catch {
|
|
81
|
+
ErrorsUtil.reject(reject, context: "Error getting installed campaigns", error)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@objc public func openInStore(_ campaignDictionary: NSDictionary,
|
|
87
|
+
useInlineInstall: Bool,
|
|
88
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
89
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
90
|
+
Task {
|
|
91
|
+
let campaign: PlaytimeCampaign
|
|
92
|
+
|
|
93
|
+
do {
|
|
94
|
+
campaign = try PlaytimeCampaign(JSONObject: campaignDictionary as! [AnyHashable: Any])
|
|
95
|
+
} catch {
|
|
96
|
+
ErrorsUtil.reject(reject, context: "Invalid parameters for openInStore", error)
|
|
97
|
+
return
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
do {
|
|
101
|
+
try await PlaytimeStudio.openInStore(campaign: campaign, useInlineInstall: useInlineInstall)
|
|
102
|
+
resolve(nil)
|
|
103
|
+
} catch {
|
|
104
|
+
ErrorsUtil.reject(reject, context: "Open store error", error)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
@objc public func openInstalledCampaign(_ campaignDictionary: NSDictionary,
|
|
110
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
111
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
112
|
+
Task {
|
|
113
|
+
let campaign: PlaytimeCampaign
|
|
114
|
+
|
|
115
|
+
do {
|
|
116
|
+
campaign = try PlaytimeCampaign(JSONObject: campaignDictionary as! [AnyHashable: Any])
|
|
117
|
+
} catch {
|
|
118
|
+
ErrorsUtil.reject(reject, context: "Invalid parameters for openInstalledCampaign", error)
|
|
119
|
+
return
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
do {
|
|
123
|
+
try await PlaytimeStudio.openInstalledCampaign(campaign: campaign)
|
|
124
|
+
resolve(nil)
|
|
125
|
+
} catch {
|
|
126
|
+
ErrorsUtil.reject(reject, context: "Open installed campaign error", error)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
@objc public func openChatbot(_ campaignDictionary: NSDictionary?,
|
|
132
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
133
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
134
|
+
Task {
|
|
135
|
+
var campaign: PlaytimeCampaign?
|
|
136
|
+
|
|
137
|
+
if let campaignDictionary = campaignDictionary {
|
|
138
|
+
do {
|
|
139
|
+
campaign = try PlaytimeCampaign(JSONObject: campaignDictionary as! [AnyHashable: Any])
|
|
140
|
+
} catch {
|
|
141
|
+
ErrorsUtil.reject(reject, context: "Invalid parameters for openChatbot", error)
|
|
142
|
+
return
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
let resolvedCampaign = campaign
|
|
147
|
+
|
|
148
|
+
do {
|
|
149
|
+
try await PlaytimeStudio.openChatbot(campaign: resolvedCampaign)
|
|
150
|
+
resolve(nil)
|
|
151
|
+
} catch {
|
|
152
|
+
ErrorsUtil.reject(reject, context: "Open chatbot error", error)
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
@objc public func resetRewardsConnect(_ resolve: @escaping RCTPromiseResolveBlock,
|
|
158
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
159
|
+
Task {
|
|
160
|
+
do {
|
|
161
|
+
try await PlaytimeStudio.resetRewardsConnect()
|
|
162
|
+
resolve(nil)
|
|
163
|
+
} catch {
|
|
164
|
+
ErrorsUtil.reject(reject, context: "Error resetting rewards connect", error)
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
@objc public func executeCampaignImpression(_ campaignDictionary: NSDictionary,
|
|
170
|
+
impressionType: Double,
|
|
171
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
172
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
173
|
+
Task {
|
|
174
|
+
let campaign: PlaytimeCampaign
|
|
175
|
+
|
|
176
|
+
do {
|
|
177
|
+
campaign = try PlaytimeCampaign(JSONObject: campaignDictionary as! [AnyHashable: Any])
|
|
178
|
+
} catch {
|
|
179
|
+
ErrorsUtil.reject(reject, context: "Invalid parameters for executeCampaignImpression", error)
|
|
180
|
+
return
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
let type: PlaytimeImpressionType = (Int(impressionType) == 1) ? .engaged : .default
|
|
184
|
+
|
|
185
|
+
do {
|
|
186
|
+
try await PlaytimeStudio.executeCampaignImpression(campaign: campaign, impressionType: type)
|
|
187
|
+
resolve(nil)
|
|
188
|
+
} catch {
|
|
189
|
+
ErrorsUtil.reject(reject, context: "Execute campaign impression error", error)
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
@objc public func executeOfferImpression(_ token: String,
|
|
195
|
+
appID: String,
|
|
196
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
197
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
198
|
+
Task {
|
|
199
|
+
do {
|
|
200
|
+
try await PlaytimeStudio.executeOfferImpression(token: token, appID: appID)
|
|
201
|
+
resolve(nil)
|
|
202
|
+
} catch {
|
|
203
|
+
ErrorsUtil.reject(reject, context: "Error executing offer impression", error)
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
@objc public func registerRewardsConnect(_ resolve: @escaping RCTPromiseResolveBlock,
|
|
209
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
210
|
+
Task {
|
|
211
|
+
do {
|
|
212
|
+
try await PlaytimeStudio.registerRewardsConnect()
|
|
213
|
+
resolve(nil)
|
|
214
|
+
} catch {
|
|
215
|
+
ErrorsUtil.reject(reject, context: "Error registering for rewards connect", error)
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
@objc public func showCampaignDetails(_ campaignDictionary: NSDictionary,
|
|
221
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
222
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
223
|
+
Task {
|
|
224
|
+
let campaign: PlaytimeCampaign
|
|
225
|
+
|
|
226
|
+
do {
|
|
227
|
+
campaign = try PlaytimeCampaign(JSONObject: campaignDictionary as! [AnyHashable: Any])
|
|
228
|
+
} catch {
|
|
229
|
+
ErrorsUtil.reject(reject, context: "Invalid parameters for showCampaignDetails", error)
|
|
230
|
+
return
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
do {
|
|
234
|
+
try await PlaytimeStudio.showCampaignDetails(campaign: campaign)
|
|
235
|
+
resolve(nil)
|
|
236
|
+
} catch {
|
|
237
|
+
ErrorsUtil.reject(reject, context: "Showing campaign details error", error)
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
@objc public func showOfferDetails(_ token: String,
|
|
243
|
+
appID: String,
|
|
244
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
245
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
246
|
+
Task {
|
|
247
|
+
do {
|
|
248
|
+
try await PlaytimeStudio.showOfferDetails(token: token, appID: appID)
|
|
249
|
+
resolve(nil)
|
|
250
|
+
} catch {
|
|
251
|
+
ErrorsUtil.reject(reject, context: "Showing offer details error", error)
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
@objc public func showInstalledCampaigns(_ resolve: @escaping RCTPromiseResolveBlock,
|
|
257
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
258
|
+
Task {
|
|
259
|
+
do {
|
|
260
|
+
try await PlaytimeStudio.showInstalledCampaigns()
|
|
261
|
+
resolve(nil)
|
|
262
|
+
} catch {
|
|
263
|
+
ErrorsUtil.reject(reject, context: "Error showing installed campaigns", error)
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
@objc public func showPermissionsPrompt(_ resolve: @escaping RCTPromiseResolveBlock,
|
|
269
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
270
|
+
ErrorsUtil.rejectUnsupported("showPermissionsPrompt", reject)
|
|
271
|
+
}
|
|
272
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
#import <React/RCTBridge.h>
|
|
2
|
+
#import <React/RCTBridgeModule.h>
|
|
3
|
+
#import <React/RCTLog.h>
|
|
4
|
+
|
|
5
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
6
|
+
// Generated spec header (produced by Codegen for codegenConfig name
|
|
7
|
+
// "RNPlaytimeSdkSpec"). Only available on the New Architecture.
|
|
8
|
+
#import "RNPlaytimeSdkSpec.h"
|
|
9
|
+
#endif
|
|
10
|
+
|
|
11
|
+
// Generated Swift umbrella header (module name derived from the pod name
|
|
12
|
+
// "react-native-adjoe-sdk"). Only exists after a build. The angle-bracket form
|
|
13
|
+
// resolves when the pod builds as a framework (use_frameworks! :linkage =>
|
|
14
|
+
// :static, required by Firebase and common in Expo); the quoted form resolves
|
|
15
|
+
// when it builds as a plain static library.
|
|
16
|
+
#if __has_include(<react_native_adjoe_sdk/react_native_adjoe_sdk-Swift.h>)
|
|
17
|
+
#import <react_native_adjoe_sdk/react_native_adjoe_sdk-Swift.h>
|
|
18
|
+
#else
|
|
19
|
+
#import "react_native_adjoe_sdk-Swift.h"
|
|
20
|
+
#endif
|
|
21
|
+
|
|
22
|
+
// The module always conforms to `RCTBridgeModule` so it registers on the legacy
|
|
23
|
+
// Native Modules registry (Old Architecture). On the New Architecture it also
|
|
24
|
+
// conforms to the Codegen-generated spec protocol via the class extension below.
|
|
25
|
+
@interface RNPlaytimeBasic : NSObject <RCTBridgeModule>
|
|
26
|
+
@end
|
|
27
|
+
|
|
28
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
29
|
+
@interface RNPlaytimeBasic () <NativeRNPlaytimeSdkSpec>
|
|
30
|
+
@end
|
|
31
|
+
#endif
|
|
32
|
+
|
|
33
|
+
@implementation RNPlaytimeBasic {
|
|
34
|
+
PlaytimeSdkImpl *_impl;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@synthesize bridge = _bridge;
|
|
38
|
+
|
|
39
|
+
// Use the same name as on Android for compatibility.
|
|
40
|
+
RCT_EXPORT_MODULE(RNPlaytimeSdk)
|
|
41
|
+
|
|
42
|
+
// The device event name under which SDK events are delivered to JavaScript. Mirrors the
|
|
43
|
+
// Android constant and the JS NativeEventEmitter subscription.
|
|
44
|
+
static NSString *const kPlaytimeEventName = @"onPlaytimeEvent";
|
|
45
|
+
|
|
46
|
+
- (instancetype)init
|
|
47
|
+
{
|
|
48
|
+
if (self = [super init]) {
|
|
49
|
+
_impl = [PlaytimeSdkImpl new];
|
|
50
|
+
|
|
51
|
+
// Forward SDK events emitted by the Swift impl to JavaScript as a device event. A
|
|
52
|
+
// publisher's JS listener object cannot cross the bridge, so the JS NativeEventEmitter
|
|
53
|
+
// relays this device event back to the registered listener's `didReceive` callback.
|
|
54
|
+
__weak __typeof(self) weakSelf = self;
|
|
55
|
+
_impl.onEvent = ^(NSDictionary *payload) {
|
|
56
|
+
__strong __typeof(weakSelf) strongSelf = weakSelf;
|
|
57
|
+
[strongSelf->_bridge enqueueJSCall:@"RCTDeviceEventEmitter"
|
|
58
|
+
method:@"emit"
|
|
59
|
+
args:@[kPlaytimeEventName, payload ?: @{}]
|
|
60
|
+
completion:NULL];
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return self;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
+ (BOOL)requiresMainQueueSetup
|
|
67
|
+
{
|
|
68
|
+
return YES;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// MARK: - Basic integration
|
|
72
|
+
|
|
73
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
74
|
+
|
|
75
|
+
- (void)initPlaytime:(NSDictionary *)options
|
|
76
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
77
|
+
reject:(RCTPromiseRejectBlock)reject
|
|
78
|
+
{
|
|
79
|
+
[_impl initPlaytime:options resolve:resolve reject:reject];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
- (void)showCatalog:(NSDictionary *)catalogOptions
|
|
83
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
84
|
+
reject:(RCTPromiseRejectBlock)reject
|
|
85
|
+
{
|
|
86
|
+
[_impl showCatalog:catalogOptions resolve:resolve reject:reject];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
- (void)getStatus:(RCTPromiseResolveBlock)resolve
|
|
90
|
+
reject:(RCTPromiseRejectBlock)reject
|
|
91
|
+
{
|
|
92
|
+
[_impl getStatus:resolve reject:reject];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
- (void)teardown:(RCTPromiseResolveBlock)resolve
|
|
96
|
+
reject:(RCTPromiseRejectBlock)reject
|
|
97
|
+
{
|
|
98
|
+
[_impl teardown:resolve reject:reject];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
- (void)executeImpressionEvent:(NSDictionary *)catalogPlacement
|
|
102
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
103
|
+
reject:(RCTPromiseRejectBlock)reject
|
|
104
|
+
{
|
|
105
|
+
[_impl executeImpressionEvent:catalogPlacement resolve:resolve reject:reject];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
- (void)addEventListener:(RCTPromiseResolveBlock)resolve
|
|
109
|
+
reject:(RCTPromiseRejectBlock)reject
|
|
110
|
+
{
|
|
111
|
+
[_impl addEventListener:resolve reject:reject];
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
- (void)removeEventListener:(RCTPromiseResolveBlock)resolve
|
|
115
|
+
reject:(RCTPromiseRejectBlock)reject
|
|
116
|
+
{
|
|
117
|
+
[_impl removeEventListener:resolve reject:reject];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Required by the NativeEventEmitter contract. Event delivery is driven by the SDK
|
|
121
|
+
// listener, so these are no-ops; they exist so the JS emitter has a native counterpart.
|
|
122
|
+
- (void)addListener:(NSString *)eventName {}
|
|
123
|
+
- (void)removeListeners:(double)count {}
|
|
124
|
+
|
|
125
|
+
// MARK: - TurboModule
|
|
126
|
+
|
|
127
|
+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
128
|
+
(const facebook::react::ObjCTurboModule::InitParams &)params
|
|
129
|
+
{
|
|
130
|
+
return std::make_shared<facebook::react::NativeRNPlaytimeSdkSpecJSI>(params);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
#else // RCT_NEW_ARCH_ENABLED not defined -> Old Architecture (legacy bridge)
|
|
134
|
+
|
|
135
|
+
RCT_EXPORT_METHOD(initPlaytime:(NSDictionary *)options
|
|
136
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
137
|
+
reject:(RCTPromiseRejectBlock)reject)
|
|
138
|
+
{
|
|
139
|
+
[_impl initPlaytime:options resolve:resolve reject:reject];
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
RCT_EXPORT_METHOD(showCatalog:(NSDictionary *)catalogOptions
|
|
143
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
144
|
+
reject:(RCTPromiseRejectBlock)reject)
|
|
145
|
+
{
|
|
146
|
+
[_impl showCatalog:catalogOptions resolve:resolve reject:reject];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
RCT_EXPORT_METHOD(getStatus:(RCTPromiseResolveBlock)resolve
|
|
150
|
+
reject:(RCTPromiseRejectBlock)reject)
|
|
151
|
+
{
|
|
152
|
+
[_impl getStatus:resolve reject:reject];
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
RCT_EXPORT_METHOD(teardown:(RCTPromiseResolveBlock)resolve
|
|
156
|
+
reject:(RCTPromiseRejectBlock)reject)
|
|
157
|
+
{
|
|
158
|
+
[_impl teardown:resolve reject:reject];
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
RCT_EXPORT_METHOD(executeImpressionEvent:(NSDictionary *)catalogPlacement
|
|
162
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
163
|
+
reject:(RCTPromiseRejectBlock)reject)
|
|
164
|
+
{
|
|
165
|
+
[_impl executeImpressionEvent:catalogPlacement resolve:resolve reject:reject];
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
RCT_EXPORT_METHOD(addEventListener:(RCTPromiseResolveBlock)resolve
|
|
169
|
+
reject:(RCTPromiseRejectBlock)reject)
|
|
170
|
+
{
|
|
171
|
+
[_impl addEventListener:resolve reject:reject];
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
RCT_EXPORT_METHOD(removeEventListener:(RCTPromiseResolveBlock)resolve
|
|
175
|
+
reject:(RCTPromiseRejectBlock)reject)
|
|
176
|
+
{
|
|
177
|
+
[_impl removeEventListener:resolve reject:reject];
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Required by the NativeEventEmitter contract on the Old Architecture. Event delivery is
|
|
181
|
+
// driven by the SDK listener, so these are no-ops.
|
|
182
|
+
RCT_EXPORT_METHOD(addListener:(NSString *)eventName) {}
|
|
183
|
+
RCT_EXPORT_METHOD(removeListeners:(double)count) {}
|
|
184
|
+
|
|
185
|
+
#endif
|
|
186
|
+
|
|
187
|
+
@end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// RNPlaytimeHelpers.h
|
|
2
|
+
|
|
3
|
+
#import <Foundation/Foundation.h>
|
|
4
|
+
#import <PlaytimeSDK/PlaytimeSDK-Swift.h>
|
|
5
|
+
|
|
6
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
7
|
+
|
|
8
|
+
@interface RNPlaytimeHelpers : NSObject
|
|
9
|
+
|
|
10
|
+
/// Builds `InitOptions` from the JS options dictionary, injecting the wrapper identifier
|
|
11
|
+
/// that the SDK expects under the `wrapper` key and converting the user profile's
|
|
12
|
+
/// ISO 8601 `birthday` string into an `NSDate`.
|
|
13
|
+
+ (InitOptions * _Nullable)initOptionsFromDictionary:(NSDictionary *)paramsDictionary error:(NSError **)error;
|
|
14
|
+
|
|
15
|
+
/// Parses an ISO 8601 date string as sent by JavaScript. Returns nil when the value is
|
|
16
|
+
/// empty or cannot be parsed.
|
|
17
|
+
+ (NSDate * _Nullable)dateFromISOString:(NSString *)value;
|
|
18
|
+
|
|
19
|
+
@end
|
|
20
|
+
|
|
21
|
+
NS_ASSUME_NONNULL_END
|