@@ -6,7 +6,7 @@ class ApphudSdk: NSObject {
6
6
7
7
override init ( ) {
8
8
ApphudHttpClient . shared. sdkType = " reactnative " ;
9
- ApphudHttpClient . shared. sdkVersion = " 2.1 .0 " ;
9
+ ApphudHttpClient . shared. sdkVersion = " 2.2 .0 " ;
10
10
}
11
11
12
12
@objc ( start: )
@@ -35,7 +35,9 @@ class ApphudSdk: NSObject {
35
35
36
36
@objc ( logout)
37
37
func logout( ) {
38
- Apphud . logout ( )
38
+ Task {
39
+ await Apphud . logout ( )
40
+ }
39
41
}
40
42
41
43
@objc ( hasActiveSubscription: withRejecter: )
@@ -54,7 +56,18 @@ class ApphudSdk: NSObject {
54
56
resolve ( products. map { DataTransformer . skProduct ( product: $0) } ) ;
55
57
}
56
58
}
57
-
59
+
60
+
61
+ func paywalls( ) async -> [ ApphudPaywall ] {
62
+ await withCheckedContinuation { continuation in
63
+ Task { @MainActor in
64
+ Apphud . paywallsDidLoadCallback { paywalls, _ in
65
+ continuation. resume ( returning: paywalls)
66
+ }
67
+ }
68
+ }
69
+ }
70
+
58
71
@objc ( purchase: withResolver: withRejecter: )
59
72
func purchase( args: NSDictionary , resolve: @escaping RCTPromiseResolveBlock , reject: @escaping RCTPromiseRejectBlock ) -> Void {
60
73
@@ -64,9 +77,9 @@ class ApphudSdk: NSObject {
64
77
}
65
78
let paywallId = args [ " paywallId " ] as? String
66
79
67
- Task {
80
+ Task { @ MainActor in
68
81
var product : ApphudProduct ?
69
- let paywalls = await Apphud . paywalls ( )
82
+ let paywalls = await paywalls ( )
70
83
71
84
for paywall in paywalls where product == nil {
72
85
product = paywall. products. first { product in
@@ -124,35 +137,36 @@ class ApphudSdk: NSObject {
124
137
125
138
@objc ( paywalls: withRejecter: )
126
139
func paywalls( resolve: @escaping RCTPromiseResolveBlock , reject: @escaping RCTPromiseRejectBlock ) -> Void {
127
- Apphud . paywallsDidLoadCallback { paywalls in
128
- resolve (
129
- paywalls. map ( { paywall in
130
- return paywall. toMap ( ) ;
131
- } )
132
- ) ;
133
- }
140
+ Task {
141
+ let paywalls = await paywalls ( )
142
+ resolve (
143
+ paywalls. map ( { paywall in
144
+ return paywall. toMap ( ) ;
145
+ } )
146
+ ) ;
147
+ }
134
148
}
135
149
136
150
@objc ( paywallShown: )
137
151
func paywallShown( identifier: String ) {
138
152
print ( " Paywall Shown: \( identifier) " )
139
153
Task {
140
- if let paywall = await Apphud . paywalls ( ) . first ( where: { $0. identifier == identifier } ) {
154
+ if let paywall = await paywalls ( ) . first ( where: { $0. identifier == identifier } ) {
141
155
Apphud . paywallShown ( paywall)
142
156
}
143
157
}
144
158
}
145
159
146
- @objc ( paywallClosed: )
147
- func paywallClosed( identifier: String ) {
148
- Task {
149
- if let paywall = await Apphud . paywalls ( ) . first ( where: { $0. identifier == identifier } ) {
150
- Apphud . paywallClosed ( paywall)
151
- }
152
- }
153
- }
160
+ @objc ( paywallClosed: )
161
+ func paywallClosed( identifier: String ) {
162
+ Task {
163
+ if let paywall = await paywalls ( ) . first ( where: { $0. identifier == identifier } ) {
164
+ Apphud . paywallClosed ( paywall)
165
+ }
166
+ }
167
+ }
154
168
155
- @objc ( subscription: withRejecter: )
169
+ @ MainActor @objc ( subscription: withRejecter: )
156
170
func subscription( resolve: RCTPromiseResolveBlock , reject: RCTPromiseRejectBlock ) -> Void {
157
171
guard let subscription = Apphud . subscription ( ) else {
158
172
reject ( " Error " , " User has no subscriptions " , nil )
@@ -162,28 +176,29 @@ class ApphudSdk: NSObject {
162
176
resolve ( DataTransformer . apphudSubscription ( subscription: subscription) ) ;
163
177
}
164
178
165
- @objc ( subscriptions: withRejecter: )
179
+
180
+ @MainActor @objc ( subscriptions: withRejecter: )
166
181
func subscriptions( resolve: RCTPromiseResolveBlock , reject: RCTPromiseRejectBlock ) -> Void {
167
182
let subs = Apphud . subscriptions ( ) ?? [ ]
168
183
let array : Array = subs. map { DataTransformer . apphudSubscription ( subscription: $0) }
169
184
resolve ( array as NSArray )
170
185
}
171
186
172
- @objc ( isNonRenewingPurchaseActive: withResolver: withRejecter: )
187
+ @ MainActor @objc ( isNonRenewingPurchaseActive: withResolver: withRejecter: )
173
188
func isNonRenewingPurchaseActive( productIdentifier: String , resolve: RCTPromiseResolveBlock , reject: RCTPromiseRejectBlock ) -> Void {
174
189
resolve (
175
190
Apphud . isNonRenewingPurchaseActive ( productIdentifier: productIdentifier)
176
191
) ;
177
192
}
178
193
179
- @objc ( nonRenewingPurchases: withRejecter: )
194
+ @ MainActor @objc ( nonRenewingPurchases: withRejecter: )
180
195
func nonRenewingPurchases( resolve: RCTPromiseResolveBlock , reject: RCTPromiseRejectBlock ) -> Void {
181
196
let purchases = Apphud . nonRenewingPurchases ( ) ?? [ ]
182
197
let array : Array = purchases. map { DataTransformer . nonRenewingPurchase ( nonRenewingPurchase: $0) }
183
198
resolve ( array)
184
199
}
185
200
186
- @objc ( restorePurchases: withRejecter: )
201
+ @ MainActor @objc ( restorePurchases: withRejecter: )
187
202
func restorePurchases( resolve: @escaping RCTPromiseResolveBlock , reject: RCTPromiseRejectBlock ) -> Void {
188
203
Apphud . restorePurchases { ( subscriptions, purchases, error) in
189
204
resolve ( [
@@ -200,7 +215,7 @@ class ApphudSdk: NSObject {
200
215
}
201
216
}
202
217
203
- @objc ( userId: withRejecter: )
218
+ @ MainActor @objc ( userId: withRejecter: )
204
219
func userId( resolve: RCTPromiseResolveBlock , reject: RCTPromiseRejectBlock ) -> Void {
205
220
resolve (
206
221
Apphud . userID ( )
@@ -229,6 +244,17 @@ class ApphudSdk: NSObject {
229
244
230
245
Apphud . addAttribution ( data: data, from: provider, identifer: identifier) { _ in }
231
246
}
247
+
248
+ @MainActor @objc ( attributeFromWeb: withResolver: withRejecter: )
249
+ func attributeFromWeb( options: NSDictionary , resolve: @escaping RCTPromiseResolveBlock , reject: @escaping RCTPromiseRejectBlock ) -> Void {
250
+ guard let options = options as? [ String : Any ] else {
251
+ reject ( " Invalid argument " , " options must be a dictionary " , nil )
252
+ return
253
+ }
254
+ Apphud . attributeFromWeb ( data: options) { result, user in
255
+ resolve ( [ " result " : result, " user_id " : user? . userId ?? " " , " is_premium " : Apphud . hasPremiumAccess ( ) ] )
256
+ }
257
+ }
232
258
233
259
@objc ( setUserProperty: )
234
260
func setUserProperty( options: NSDictionary ) {
@@ -248,7 +274,7 @@ class ApphudSdk: NSObject {
248
274
Apphud . incrementUserProperty ( key: _key, by: by)
249
275
}
250
276
251
- @objc ( syncPurchasesInObserverMode: withRejecter: )
277
+ @ MainActor @objc ( syncPurchasesInObserverMode: withRejecter: )
252
278
func syncPurchasesInObserverMode( resolve: @escaping RCTPromiseResolveBlock , reject: RCTPromiseRejectBlock ) -> Void {
253
279
Apphud . restorePurchases { _, _, _ in
254
280
resolve ( true )
@@ -257,12 +283,12 @@ class ApphudSdk: NSObject {
257
283
258
284
@objc ( setAdvertisingIdentifier: )
259
285
func setAdvertisingIdentifier( idfa: String ) {
260
- Apphud . setAdvertisingIdentifier ( idfa)
286
+ Apphud . setDeviceIdentifiers ( idfa: idfa , idfv : UIDevice . current . identifierForVendor ? . uuidString )
261
287
}
262
288
263
289
@objc ( enableDebugLogs)
264
290
func enableDebugLogs( ) {
265
- Apphud . enableDebugLogs ( )
291
+ ApphudUtils . enableAllLogs ( )
266
292
}
267
293
268
294
@objc ( optOutOfTracking)
0 commit comments