@altcraft/react-native-sdk 0.0.5 → 1.0.0
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 +21 -120
- package/autolink.js +36 -0
- package/lib/commonjs/altcraft_sdk.js +297 -0
- package/lib/commonjs/altcraft_sdk.js.map +1 -0
- package/lib/commonjs/index.js +192 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/module/altcraft_sdk.js +292 -0
- package/lib/module/altcraft_sdk.js.map +1 -0
- package/lib/module/index.js +13 -427
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/src/altcraft_sdk.d.ts +143 -0
- package/lib/typescript/commonjs/src/altcraft_sdk.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +24 -0
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
- package/lib/typescript/module/src/altcraft_sdk.d.ts +143 -0
- package/lib/typescript/module/src/altcraft_sdk.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +24 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -0
- package/package.json +49 -95
- package/scripts/postinstall.cjs +195 -0
- package/src/altcraft_sdk.ts +337 -0
- package/src/index.ts +91 -0
- package/Sdk.podspec +0 -48
- package/android/build.gradle +0 -77
- package/android/gradle.properties +0 -5
- package/android/src/main/AndroidManifest.xml +0 -2
- package/android/src/main/java/com/altcraft/sdk/SdkEventEmitter.kt +0 -55
- package/android/src/main/java/com/altcraft/sdk/SdkModule.kt +0 -993
- package/android/src/main/java/com/altcraft/sdk/SdkPackage.kt +0 -41
- package/android/src/main/java/com/altcraft/sdk/utilities/Converter.kt +0 -326
- package/android/src/main/java/com/altcraft/sdk/utilities/Extension.kt +0 -72
- package/ios/Converter.swift +0 -640
- package/ios/Sdk.h +0 -20
- package/ios/Sdk.mm +0 -979
- package/ios/SdkModule.swift +0 -778
- package/lib/module/NativeSdk.js +0 -48
- package/lib/module/NativeSdk.js.map +0 -1
- package/lib/module/Utilities.js +0 -178
- package/lib/module/Utilities.js.map +0 -1
- package/lib/typescript/src/NativeSdk.d.ts +0 -215
- package/lib/typescript/src/NativeSdk.d.ts.map +0 -1
- package/lib/typescript/src/Utilities.d.ts +0 -47
- package/lib/typescript/src/Utilities.d.ts.map +0 -1
- package/lib/typescript/src/index.d.ts +0 -252
- package/lib/typescript/src/index.d.ts.map +0 -1
- package/react-native.config.js +0 -10
- package/src/NativeSdk.ts +0 -313
- package/src/Utilities.ts +0 -180
- package/src/index.tsx +0 -570
- /package/lib/typescript/{package.json → module/package.json} +0 -0
package/ios/Sdk.mm
DELETED
|
@@ -1,979 +0,0 @@
|
|
|
1
|
-
// Sdk.mm
|
|
2
|
-
|
|
3
|
-
#import "Sdk.h"
|
|
4
|
-
|
|
5
|
-
#ifdef RCT_NEW_ARCH_ENABLED
|
|
6
|
-
#import <ReactCommon/RCTTurboModule.h>
|
|
7
|
-
#endif
|
|
8
|
-
|
|
9
|
-
#import <Foundation/Foundation.h>
|
|
10
|
-
#import <objc/message.h>
|
|
11
|
-
#import <objc/runtime.h>
|
|
12
|
-
|
|
13
|
-
#include <optional>
|
|
14
|
-
#include <type_traits>
|
|
15
|
-
|
|
16
|
-
#if __has_include(<React/RCTBridgeModule.h>)
|
|
17
|
-
#import <React/RCTBridgeModule.h>
|
|
18
|
-
#endif
|
|
19
|
-
|
|
20
|
-
#if __has_include(<React/RCTUtils.h>)
|
|
21
|
-
#import <React/RCTUtils.h>
|
|
22
|
-
#endif
|
|
23
|
-
|
|
24
|
-
#if __has_include(<React/RCTCallableJSModules.h>)
|
|
25
|
-
#import <React/RCTCallableJSModules.h>
|
|
26
|
-
#else
|
|
27
|
-
@protocol RCTCallableJSModules <NSObject>
|
|
28
|
-
- (void)invokeModule:(NSString *)moduleName
|
|
29
|
-
method:(NSString *)methodName
|
|
30
|
-
withArgs:(NSArray *)args;
|
|
31
|
-
@end
|
|
32
|
-
#endif
|
|
33
|
-
|
|
34
|
-
#ifndef RCTPromiseResolveBlock
|
|
35
|
-
typedef void (^RCTPromiseResolveBlock)(id _Nullable result);
|
|
36
|
-
#endif
|
|
37
|
-
|
|
38
|
-
#ifndef RCTPromiseRejectBlock
|
|
39
|
-
typedef void (^RCTPromiseRejectBlock)(NSString * _Nonnull code,
|
|
40
|
-
NSString * _Nullable message,
|
|
41
|
-
NSError * _Nullable error);
|
|
42
|
-
#endif
|
|
43
|
-
|
|
44
|
-
#pragma mark - Runtime helpers
|
|
45
|
-
|
|
46
|
-
static SEL SdkSel(NSString *name) {
|
|
47
|
-
return NSSelectorFromString(name);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
static BOOL SdkResponds(id obj, SEL sel) {
|
|
51
|
-
return obj && sel && [obj respondsToSelector:sel];
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
static BOOL SdkClassResponds(Class cls, SEL sel) {
|
|
55
|
-
return cls && sel && [cls respondsToSelector:sel];
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
#pragma mark - NSNull -> nil
|
|
59
|
-
|
|
60
|
-
static inline id SdkNilIfNSNull(id v) {
|
|
61
|
-
return (v == (id)kCFNull || [v isKindOfClass:[NSNull class]]) ? nil : v;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
#pragma mark - Swift runtime bridge (no Sdk-Swift.h needed)
|
|
65
|
-
|
|
66
|
-
static Class SdkAppModuleClass(void) {
|
|
67
|
-
Class cls = NSClassFromString(@"SdkModule");
|
|
68
|
-
|
|
69
|
-
#ifdef DEBUG
|
|
70
|
-
if (!cls) {
|
|
71
|
-
int count = objc_getClassList(NULL, 0);
|
|
72
|
-
if (count > 0) {
|
|
73
|
-
Class *classes = (Class *)malloc(sizeof(Class) * (NSUInteger)count);
|
|
74
|
-
if (classes) {
|
|
75
|
-
objc_getClassList(classes, count);
|
|
76
|
-
for (int i = 0; i < count; i++) {
|
|
77
|
-
NSString *name = NSStringFromClass(classes[i]);
|
|
78
|
-
if ([name hasSuffix:@".SdkModule"] || [name isEqualToString:@"SdkModule"]) {
|
|
79
|
-
if ([name hasSuffix:@".SdkModule"]) {
|
|
80
|
-
cls = classes[i];
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
free(classes);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
#endif // DEBUG
|
|
90
|
-
|
|
91
|
-
return cls;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
static id SdkAppModuleSharedInstance(void) {
|
|
95
|
-
Class cls = SdkAppModuleClass();
|
|
96
|
-
if (!cls) return nil;
|
|
97
|
-
|
|
98
|
-
SEL sel = SdkSel(@"shared");
|
|
99
|
-
if (!SdkClassResponds(cls, sel)) return nil;
|
|
100
|
-
|
|
101
|
-
IMP imp = [cls methodForSelector:sel];
|
|
102
|
-
if (!imp) return nil;
|
|
103
|
-
|
|
104
|
-
id (*func)(id, SEL) = (id (*)(id, SEL))imp;
|
|
105
|
-
return func((id)cls, sel);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
static void EnsureProvidersInstalled(id instance) {
|
|
109
|
-
if (!instance) return;
|
|
110
|
-
|
|
111
|
-
SEL sel = SdkSel(@"ensureProvidersInstalled");
|
|
112
|
-
if (!SdkResponds(instance, sel)) return;
|
|
113
|
-
|
|
114
|
-
IMP imp = [instance methodForSelector:sel];
|
|
115
|
-
if (!imp) return;
|
|
116
|
-
|
|
117
|
-
void (*func)(id, SEL) = (void (*)(id, SEL))imp;
|
|
118
|
-
func(instance, sel);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
#pragma mark - Swift calls (UserDefaults)
|
|
122
|
-
|
|
123
|
-
static void CallSetUserDefaultsValue(id instance,
|
|
124
|
-
NSString * _Nullable suiteName,
|
|
125
|
-
NSString *key,
|
|
126
|
-
id _Nullable value) {
|
|
127
|
-
if (!instance) return;
|
|
128
|
-
|
|
129
|
-
SEL sel = SdkSel(@"setUserDefaultsValueWithSuiteName:key:value:");
|
|
130
|
-
if (!SdkResponds(instance, sel)) return;
|
|
131
|
-
|
|
132
|
-
IMP imp = [instance methodForSelector:sel];
|
|
133
|
-
if (!imp) return;
|
|
134
|
-
|
|
135
|
-
void (*func)(id, SEL, id, id, id) = (void (*)(id, SEL, id, id, id))imp;
|
|
136
|
-
func(instance, sel, suiteName, key, value);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
#pragma mark - Push token API (ONLY getPushToken / setPushToken)
|
|
140
|
-
|
|
141
|
-
static void CallGetPushToken(id instance, void (^completion)(id _Nullable tokenObjC)) {
|
|
142
|
-
if (!instance) { completion(nil); return; }
|
|
143
|
-
|
|
144
|
-
SEL sel = SdkSel(@"getPushTokenWithCompletion:");
|
|
145
|
-
if (!SdkResponds(instance, sel)) { completion(nil); return; }
|
|
146
|
-
|
|
147
|
-
IMP imp = [instance methodForSelector:sel];
|
|
148
|
-
if (!imp) { completion(nil); return; }
|
|
149
|
-
|
|
150
|
-
void (*func)(id, SEL, id) = (void (*)(id, SEL, id))imp;
|
|
151
|
-
func(instance, sel, completion);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
static void CallSetPushToken(id instance, NSString *provider, NSString * _Nullable token) {
|
|
155
|
-
if (!instance) return;
|
|
156
|
-
|
|
157
|
-
SEL sel = SdkSel(@"setPushTokenWithProvider:pushToken:");
|
|
158
|
-
if (!SdkResponds(instance, sel)) return;
|
|
159
|
-
|
|
160
|
-
IMP imp = [instance methodForSelector:sel];
|
|
161
|
-
if (!imp) return;
|
|
162
|
-
|
|
163
|
-
void (*func)(id, SEL, id, id) = (void (*)(id, SEL, id, id))imp;
|
|
164
|
-
func(instance, sel, provider, token);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
#pragma mark - Push subscription calls
|
|
168
|
-
|
|
169
|
-
static void CallPushSubscription(id instance,
|
|
170
|
-
NSString *selectorName,
|
|
171
|
-
NSNumber *sync,
|
|
172
|
-
NSDictionary *profileFields,
|
|
173
|
-
NSDictionary *customFields,
|
|
174
|
-
NSArray *cats,
|
|
175
|
-
NSNumber *replace,
|
|
176
|
-
NSNumber *skipTriggers) {
|
|
177
|
-
if (!instance) return;
|
|
178
|
-
|
|
179
|
-
SEL sel = SdkSel(selectorName);
|
|
180
|
-
if (!SdkResponds(instance, sel)) return;
|
|
181
|
-
|
|
182
|
-
IMP imp = [instance methodForSelector:sel];
|
|
183
|
-
if (!imp) return;
|
|
184
|
-
|
|
185
|
-
void (*func)(id, SEL, id, id, id, id, id, id) =
|
|
186
|
-
(void (*)(id, SEL, id, id, id, id, id, id))imp;
|
|
187
|
-
|
|
188
|
-
func(instance, sel, sync, profileFields, customFields, cats, replace, skipTriggers);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
#pragma mark - Mobile Event calls (with subscription param)
|
|
192
|
-
|
|
193
|
-
static void CallMobileEvent(id instance,
|
|
194
|
-
NSString *sid,
|
|
195
|
-
NSString *eventName,
|
|
196
|
-
NSString * _Nullable sendMessageId,
|
|
197
|
-
NSDictionary * _Nullable payload,
|
|
198
|
-
NSDictionary * _Nullable matching,
|
|
199
|
-
NSString * _Nullable matchingType,
|
|
200
|
-
NSDictionary * _Nullable profileFields,
|
|
201
|
-
NSDictionary * _Nullable subscription,
|
|
202
|
-
NSDictionary * _Nullable utm) {
|
|
203
|
-
if (!instance) return;
|
|
204
|
-
|
|
205
|
-
SEL sel = SdkSel(@"mobileEvent:eventName:sendMessageId:payload:matching:matchingType:profileFields:subscription:utm:");
|
|
206
|
-
if (!SdkResponds(instance, sel)) return;
|
|
207
|
-
|
|
208
|
-
IMP imp = [instance methodForSelector:sel];
|
|
209
|
-
if (!imp) return;
|
|
210
|
-
|
|
211
|
-
void (*func)(id, SEL, id, id, id, id, id, id, id, id, id) =
|
|
212
|
-
(void (*)(id, SEL, id, id, id, id, id, id, id, id, id))imp;
|
|
213
|
-
|
|
214
|
-
func(instance, sel, sid, eventName, sendMessageId, payload, matching, matchingType, profileFields, subscription, utm);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
#pragma mark - Promise helpers
|
|
218
|
-
|
|
219
|
-
static void CallPromise0Args(id instance,
|
|
220
|
-
NSString *selectorName,
|
|
221
|
-
RCTPromiseResolveBlock resolve,
|
|
222
|
-
RCTPromiseRejectBlock reject) {
|
|
223
|
-
if (!instance) {
|
|
224
|
-
NSError *err = [NSError errorWithDomain:@"Sdk" code:1 userInfo:@{NSLocalizedDescriptionKey:@"SdkAppModule is nil"}];
|
|
225
|
-
reject(@"SWIFT_MODULE_NOT_FOUND", @"SdkAppModule instance is nil", err);
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
SEL sel = SdkSel(selectorName);
|
|
230
|
-
if (!SdkResponds(instance, sel)) {
|
|
231
|
-
NSError *err = [NSError errorWithDomain:@"Sdk" code:22 userInfo:@{NSLocalizedDescriptionKey:@"Swift selector not found"}];
|
|
232
|
-
reject(@"METHOD_NOT_FOUND", @"method not found", err);
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
if (![NSThread isMainThread]) {
|
|
237
|
-
dispatch_async(dispatch_get_main_queue(), ^{
|
|
238
|
-
CallPromise0Args(instance, selectorName, resolve, reject);
|
|
239
|
-
});
|
|
240
|
-
return;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
IMP imp = [instance methodForSelector:sel];
|
|
244
|
-
if (!imp) {
|
|
245
|
-
NSMethodSignature *sig = [instance methodSignatureForSelector:sel];
|
|
246
|
-
if (!sig) {
|
|
247
|
-
NSError *err = [NSError errorWithDomain:@"Sdk" code:20 userInfo:@{NSLocalizedDescriptionKey:@"No signature"}];
|
|
248
|
-
reject(@"METHOD_SIGNATURE_NOT_FOUND", @"method signature not found", err);
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
NSInvocation *inv = [NSInvocation invocationWithMethodSignature:sig];
|
|
253
|
-
[inv setTarget:instance];
|
|
254
|
-
[inv setSelector:sel];
|
|
255
|
-
RCTPromiseResolveBlock res = resolve;
|
|
256
|
-
RCTPromiseRejectBlock rej = reject;
|
|
257
|
-
[inv setArgument:&res atIndex:2];
|
|
258
|
-
[inv setArgument:&rej atIndex:3];
|
|
259
|
-
[inv invoke];
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
void (*func)(id, SEL, RCTPromiseResolveBlock, RCTPromiseRejectBlock) =
|
|
264
|
-
(void (*)(id, SEL, RCTPromiseResolveBlock, RCTPromiseRejectBlock))imp;
|
|
265
|
-
|
|
266
|
-
func(instance, sel, resolve, reject);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
static void CallPromise1StringArg(id instance,
|
|
270
|
-
NSString *selectorName,
|
|
271
|
-
NSString * _Nullable arg,
|
|
272
|
-
RCTPromiseResolveBlock resolve,
|
|
273
|
-
RCTPromiseRejectBlock reject) {
|
|
274
|
-
if (!instance) {
|
|
275
|
-
NSError *err = [NSError errorWithDomain:@"Sdk" code:1 userInfo:@{NSLocalizedDescriptionKey:@"SdkAppModule is nil"}];
|
|
276
|
-
reject(@"SWIFT_MODULE_NOT_FOUND", @"SdkAppModule instance is nil", err);
|
|
277
|
-
return;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
SEL sel = SdkSel(selectorName);
|
|
281
|
-
if (!SdkResponds(instance, sel)) {
|
|
282
|
-
NSError *err = [NSError errorWithDomain:@"Sdk" code:23 userInfo:@{NSLocalizedDescriptionKey:@"Swift selector not found"}];
|
|
283
|
-
reject(@"METHOD_NOT_FOUND", @"method not found", err);
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
if (![NSThread isMainThread]) {
|
|
288
|
-
NSString *a = arg;
|
|
289
|
-
dispatch_async(dispatch_get_main_queue(), ^{
|
|
290
|
-
CallPromise1StringArg(instance, selectorName, a, resolve, reject);
|
|
291
|
-
});
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
IMP imp = [instance methodForSelector:sel];
|
|
296
|
-
if (!imp) {
|
|
297
|
-
NSMethodSignature *sig = [instance methodSignatureForSelector:sel];
|
|
298
|
-
if (!sig) {
|
|
299
|
-
NSError *err = [NSError errorWithDomain:@"Sdk" code:21 userInfo:@{NSLocalizedDescriptionKey:@"No signature"}];
|
|
300
|
-
reject(@"METHOD_SIGNATURE_NOT_FOUND", @"method signature not found", err);
|
|
301
|
-
return;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
NSInvocation *inv = [NSInvocation invocationWithMethodSignature:sig];
|
|
305
|
-
[inv setTarget:instance];
|
|
306
|
-
[inv setSelector:sel];
|
|
307
|
-
NSString *a = arg;
|
|
308
|
-
RCTPromiseResolveBlock res = resolve;
|
|
309
|
-
RCTPromiseRejectBlock rej = reject;
|
|
310
|
-
[inv setArgument:&a atIndex:2];
|
|
311
|
-
[inv setArgument:&res atIndex:3];
|
|
312
|
-
[inv setArgument:&rej atIndex:4];
|
|
313
|
-
[inv invoke];
|
|
314
|
-
return;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
void (*func)(id, SEL, NSString *, RCTPromiseResolveBlock, RCTPromiseRejectBlock) =
|
|
318
|
-
(void (*)(id, SEL, NSString *, RCTPromiseResolveBlock, RCTPromiseRejectBlock))imp;
|
|
319
|
-
|
|
320
|
-
func(instance, sel, arg, resolve, reject);
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
#pragma mark - Initialize / Clear
|
|
324
|
-
|
|
325
|
-
static void CallInitializeBySelector(id instance,
|
|
326
|
-
SEL sel,
|
|
327
|
-
NSDictionary *config,
|
|
328
|
-
RCTPromiseResolveBlock resolve,
|
|
329
|
-
RCTPromiseRejectBlock reject) {
|
|
330
|
-
if (![NSThread isMainThread]) {
|
|
331
|
-
NSDictionary *cfg = config ?: @{};
|
|
332
|
-
dispatch_async(dispatch_get_main_queue(), ^{
|
|
333
|
-
CallInitializeBySelector(instance, sel, cfg, resolve, reject);
|
|
334
|
-
});
|
|
335
|
-
return;
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
IMP imp = [instance methodForSelector:sel];
|
|
339
|
-
if (!imp) {
|
|
340
|
-
NSMethodSignature *sig = [instance methodSignatureForSelector:sel];
|
|
341
|
-
if (!sig) {
|
|
342
|
-
NSError *err = [NSError errorWithDomain:@"Sdk" code:7 userInfo:@{NSLocalizedDescriptionKey:@"No signature"}];
|
|
343
|
-
reject(@"INIT_SIGNATURE_NOT_FOUND", @"initialize signature not found", err);
|
|
344
|
-
return;
|
|
345
|
-
}
|
|
346
|
-
NSInvocation *inv = [NSInvocation invocationWithMethodSignature:sig];
|
|
347
|
-
[inv setTarget:instance];
|
|
348
|
-
[inv setSelector:sel];
|
|
349
|
-
NSDictionary *cfg = config ?: @{};
|
|
350
|
-
RCTPromiseResolveBlock res = resolve;
|
|
351
|
-
RCTPromiseRejectBlock rej = reject;
|
|
352
|
-
[inv setArgument:&cfg atIndex:2];
|
|
353
|
-
[inv setArgument:&res atIndex:3];
|
|
354
|
-
[inv setArgument:&rej atIndex:4];
|
|
355
|
-
[inv invoke];
|
|
356
|
-
return;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
void (*func)(id, SEL, NSDictionary *, RCTPromiseResolveBlock, RCTPromiseRejectBlock) =
|
|
360
|
-
(void (*)(id, SEL, NSDictionary *, RCTPromiseResolveBlock, RCTPromiseRejectBlock))imp;
|
|
361
|
-
|
|
362
|
-
NSDictionary *safeCfg = config ?: @{};
|
|
363
|
-
func(instance, sel, safeCfg, resolve, reject);
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
static void CallInitialize(id instance,
|
|
367
|
-
NSDictionary *config,
|
|
368
|
-
RCTPromiseResolveBlock resolve,
|
|
369
|
-
RCTPromiseRejectBlock reject) {
|
|
370
|
-
if (!instance) {
|
|
371
|
-
NSError *err = [NSError errorWithDomain:@"Sdk" code:1 userInfo:@{NSLocalizedDescriptionKey:@"SdkAppModule is nil"}];
|
|
372
|
-
reject(@"SWIFT_MODULE_NOT_FOUND", @"SdkAppModule instance is nil", err);
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
SEL sel = SdkSel(@"initializeWithConfig:resolver:rejecter:");
|
|
377
|
-
if (!SdkResponds(instance, sel)) {
|
|
378
|
-
NSError *err = [NSError errorWithDomain:@"Sdk" code:6 userInfo:@{NSLocalizedDescriptionKey:@"initialize selector not found"}];
|
|
379
|
-
reject(@"INIT_METHOD_NOT_FOUND", @"initialize method not found", err);
|
|
380
|
-
return;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
CallInitializeBySelector(instance, sel, config, resolve, reject);
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
static void CallClear(id instance,
|
|
387
|
-
RCTPromiseResolveBlock resolve,
|
|
388
|
-
RCTPromiseRejectBlock reject) {
|
|
389
|
-
CallPromise0Args(instance, @"clearWithResolver:rejecter:", resolve, reject);
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
#pragma mark - Typed config -> NSDictionary (New Arch)
|
|
393
|
-
|
|
394
|
-
#ifdef RCT_NEW_ARCH_ENABLED
|
|
395
|
-
|
|
396
|
-
template <typename T>
|
|
397
|
-
struct SdkIsStdOptional : std::false_type {};
|
|
398
|
-
|
|
399
|
-
template <typename T>
|
|
400
|
-
struct SdkIsStdOptional<std::optional<T>> : std::true_type {};
|
|
401
|
-
|
|
402
|
-
template <typename T>
|
|
403
|
-
static NSString *SdkGetStringOrNil(const T &v) {
|
|
404
|
-
using D = std::decay_t<T>;
|
|
405
|
-
if constexpr (std::is_same_v<D, NSString *>) {
|
|
406
|
-
return v;
|
|
407
|
-
} else if constexpr (SdkIsStdOptional<D>::value) {
|
|
408
|
-
return v.has_value() ? v.value() : nil;
|
|
409
|
-
} else {
|
|
410
|
-
return nil;
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
template <typename T>
|
|
415
|
-
static NSNumber *SdkGetBoolNumberOrNil(const T &v) {
|
|
416
|
-
using D = std::decay_t<T>;
|
|
417
|
-
if constexpr (std::is_same_v<D, bool>) {
|
|
418
|
-
return @(v);
|
|
419
|
-
} else if constexpr (SdkIsStdOptional<D>::value) {
|
|
420
|
-
return v.has_value() ? @(v.value()) : nil;
|
|
421
|
-
} else {
|
|
422
|
-
return nil;
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
#import <limits.h>
|
|
427
|
-
|
|
428
|
-
static NSArray *SdkLazyVectorToNSArray(const facebook::react::LazyVector<NSString *> &vec) {
|
|
429
|
-
const size_t n = vec.size();
|
|
430
|
-
const size_t capped = (n > (size_t)INT_MAX) ? (size_t)INT_MAX : n;
|
|
431
|
-
|
|
432
|
-
NSMutableArray *arr = [NSMutableArray arrayWithCapacity:(NSUInteger)capped];
|
|
433
|
-
for (int i = 0; i < (int)capped; i++) {
|
|
434
|
-
NSString *s = vec[i];
|
|
435
|
-
[arr addObject:(s ? s : (id)kCFNull)];
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
return arr;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
template <typename T>
|
|
442
|
-
static NSArray *SdkGetStringArrayOrNil(const T &v) {
|
|
443
|
-
using D = std::decay_t<T>;
|
|
444
|
-
if constexpr (std::is_same_v<D, facebook::react::LazyVector<NSString *>>) {
|
|
445
|
-
return SdkLazyVectorToNSArray(v);
|
|
446
|
-
} else if constexpr (SdkIsStdOptional<D>::value) {
|
|
447
|
-
return v.has_value() ? SdkLazyVectorToNSArray(v.value()) : nil;
|
|
448
|
-
} else {
|
|
449
|
-
return nil;
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
template <typename T>
|
|
454
|
-
static NSDictionary *SdkGetAppInfoDictOrNil(const T &v) {
|
|
455
|
-
using D = std::decay_t<T>;
|
|
456
|
-
|
|
457
|
-
auto makeDict = [](NSString *appID, NSString *appIID, NSString *appVer) -> NSDictionary * {
|
|
458
|
-
if ((!appID || appID.length == 0) && (!appIID || appIID.length == 0) && (!appVer || appVer.length == 0)) {
|
|
459
|
-
return nil;
|
|
460
|
-
}
|
|
461
|
-
return @{
|
|
462
|
-
@"appID": appID ?: (id)kCFNull,
|
|
463
|
-
@"appIID": appIID ?: (id)kCFNull,
|
|
464
|
-
@"appVer": appVer ?: (id)kCFNull,
|
|
465
|
-
};
|
|
466
|
-
};
|
|
467
|
-
|
|
468
|
-
if constexpr (SdkIsStdOptional<D>::value) {
|
|
469
|
-
if (!v.has_value()) return nil;
|
|
470
|
-
const auto &info = v.value();
|
|
471
|
-
return makeDict(info.appID(), info.appIID(), info.appVer());
|
|
472
|
-
} else {
|
|
473
|
-
return makeDict(v.appID(), v.appIID(), v.appVer());
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
static NSDictionary *SdkConvertAltcraftConfigToNSDictionary(JS::NativeSdk::AltcraftConfig &cfg) {
|
|
478
|
-
NSString *apiUrl = cfg.apiUrl();
|
|
479
|
-
NSString *rToken = SdkGetStringOrNil(cfg.rToken());
|
|
480
|
-
NSNumber *enableLogging = SdkGetBoolNumberOrNil(cfg.enableLogging());
|
|
481
|
-
NSArray *providerPriorityList = SdkGetStringArrayOrNil(cfg.providerPriorityList());
|
|
482
|
-
NSDictionary *appInfo = SdkGetAppInfoDictOrNil(cfg.appInfo());
|
|
483
|
-
|
|
484
|
-
NSMutableDictionary *dict = [NSMutableDictionary new];
|
|
485
|
-
dict[@"apiUrl"] = apiUrl ?: @"";
|
|
486
|
-
dict[@"rToken"] = rToken ?: (id)kCFNull;
|
|
487
|
-
dict[@"appInfo"] = appInfo ?: (id)kCFNull;
|
|
488
|
-
dict[@"providerPriorityList"] = providerPriorityList ?: (id)kCFNull;
|
|
489
|
-
dict[@"enableLogging"] = enableLogging ?: (id)kCFNull;
|
|
490
|
-
return dict;
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
#pragma mark - UTM typed (New Arch) -> NSDictionary
|
|
494
|
-
|
|
495
|
-
static inline NSString *SdkNonEmptyOrNil(NSString *s) {
|
|
496
|
-
if (!s) return nil;
|
|
497
|
-
return (s.length > 0) ? s : nil;
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
static NSDictionary * _Nullable SdkConvertUTMToNSDictionary(JS::NativeSdk::UTM &utm) {
|
|
501
|
-
NSString *campaign = SdkNonEmptyOrNil(utm.campaign());
|
|
502
|
-
NSString *content = SdkNonEmptyOrNil(utm.content());
|
|
503
|
-
NSString *keyword = SdkNonEmptyOrNil(utm.keyword());
|
|
504
|
-
NSString *medium = SdkNonEmptyOrNil(utm.medium());
|
|
505
|
-
NSString *source = SdkNonEmptyOrNil(utm.source());
|
|
506
|
-
NSString *temp = SdkNonEmptyOrNil(utm.temp());
|
|
507
|
-
|
|
508
|
-
if (!campaign && !content && !keyword && !medium && !source && !temp) {
|
|
509
|
-
return nil;
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
return @{
|
|
513
|
-
@"campaign": campaign ?: (id)kCFNull,
|
|
514
|
-
@"content": content ?: (id)kCFNull,
|
|
515
|
-
@"keyword": keyword ?: (id)kCFNull,
|
|
516
|
-
@"medium": medium ?: (id)kCFNull,
|
|
517
|
-
@"source": source ?: (id)kCFNull,
|
|
518
|
-
@"temp": temp ?: (id)kCFNull,
|
|
519
|
-
};
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
#endif // RCT_NEW_ARCH_ENABLED
|
|
523
|
-
|
|
524
|
-
#pragma mark - Module implementation
|
|
525
|
-
|
|
526
|
-
@implementation Sdk
|
|
527
|
-
|
|
528
|
-
#ifdef RCT_NEW_ARCH_ENABLED
|
|
529
|
-
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
530
|
-
(const facebook::react::ObjCTurboModule::InitParams &)params
|
|
531
|
-
{
|
|
532
|
-
return std::make_shared<facebook::react::NativeSdkSpecJSI>(params);
|
|
533
|
-
}
|
|
534
|
-
#endif // RCT_NEW_ARCH_ENABLED
|
|
535
|
-
|
|
536
|
-
+ (NSString *)moduleName { return @"Sdk"; }
|
|
537
|
-
|
|
538
|
-
#ifdef RCT_NEW_ARCH_ENABLED
|
|
539
|
-
- (void)initialize:(JS::NativeSdk::AltcraftConfig &)config
|
|
540
|
-
resolve:(RCTPromiseResolveBlock)resolve
|
|
541
|
-
reject:(RCTPromiseRejectBlock)reject
|
|
542
|
-
{
|
|
543
|
-
id module = SdkAppModuleSharedInstance();
|
|
544
|
-
EnsureProvidersInstalled(module);
|
|
545
|
-
|
|
546
|
-
NSDictionary *swiftConfig = SdkConvertAltcraftConfigToNSDictionary(config);
|
|
547
|
-
CallInitialize(module, swiftConfig, resolve, reject);
|
|
548
|
-
}
|
|
549
|
-
#endif // RCT_NEW_ARCH_ENABLED
|
|
550
|
-
|
|
551
|
-
- (void)addListener:(NSString *)eventName { (void)eventName; }
|
|
552
|
-
- (void)removeListeners:(double)count { (void)count; }
|
|
553
|
-
|
|
554
|
-
#pragma mark - Events API (Swift emits; ObjC++ only forwards method calls)
|
|
555
|
-
|
|
556
|
-
- (void)subscribeToEvents
|
|
557
|
-
{
|
|
558
|
-
id module = SdkAppModuleSharedInstance();
|
|
559
|
-
EnsureProvidersInstalled(module);
|
|
560
|
-
|
|
561
|
-
SEL sel = SdkSel(@"subscribeToEvents");
|
|
562
|
-
if (!SdkResponds(module, sel)) return;
|
|
563
|
-
|
|
564
|
-
IMP imp = [module methodForSelector:sel];
|
|
565
|
-
if (!imp) return;
|
|
566
|
-
|
|
567
|
-
void (*func)(id, SEL) = (void (*)(id, SEL))imp;
|
|
568
|
-
func(module, sel);
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
- (void)unsubscribeFromEvent
|
|
572
|
-
{
|
|
573
|
-
id module = SdkAppModuleSharedInstance();
|
|
574
|
-
EnsureProvidersInstalled(module);
|
|
575
|
-
|
|
576
|
-
SEL sel = SdkSel(@"unsubscribeFromEvent");
|
|
577
|
-
if (!SdkResponds(module, sel)) return;
|
|
578
|
-
|
|
579
|
-
IMP imp = [module methodForSelector:sel];
|
|
580
|
-
if (!imp) return;
|
|
581
|
-
|
|
582
|
-
void (*func)(id, SEL) = (void (*)(id, SEL))imp;
|
|
583
|
-
func(module, sel);
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
#pragma mark - Subscription (void)
|
|
587
|
-
|
|
588
|
-
- (void)pushSubscribe:(NSNumber *)sync
|
|
589
|
-
profileFields:(NSDictionary *)profileFields
|
|
590
|
-
customFields:(NSDictionary *)customFields
|
|
591
|
-
cats:(NSArray *)cats
|
|
592
|
-
replace:(NSNumber *)replace
|
|
593
|
-
skipTriggers:(NSNumber *)skipTriggers
|
|
594
|
-
{
|
|
595
|
-
id module = SdkAppModuleSharedInstance();
|
|
596
|
-
EnsureProvidersInstalled(module);
|
|
597
|
-
|
|
598
|
-
CallPushSubscription(module,
|
|
599
|
-
@"pushSubscribe:profileFields:customFields:cats:replace:skipTriggers:",
|
|
600
|
-
(NSNumber *)SdkNilIfNSNull(sync),
|
|
601
|
-
(NSDictionary *)SdkNilIfNSNull(profileFields),
|
|
602
|
-
(NSDictionary *)SdkNilIfNSNull(customFields),
|
|
603
|
-
(NSArray *)SdkNilIfNSNull(cats),
|
|
604
|
-
(NSNumber *)SdkNilIfNSNull(replace),
|
|
605
|
-
(NSNumber *)SdkNilIfNSNull(skipTriggers));
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
- (void)pushSuspend:(NSNumber *)sync
|
|
609
|
-
profileFields:(NSDictionary *)profileFields
|
|
610
|
-
customFields:(NSDictionary *)customFields
|
|
611
|
-
cats:(NSArray *)cats
|
|
612
|
-
replace:(NSNumber *)replace
|
|
613
|
-
skipTriggers:(NSNumber *)skipTriggers
|
|
614
|
-
{
|
|
615
|
-
id module = SdkAppModuleSharedInstance();
|
|
616
|
-
EnsureProvidersInstalled(module);
|
|
617
|
-
|
|
618
|
-
CallPushSubscription(module,
|
|
619
|
-
@"pushSuspend:profileFields:customFields:cats:replace:skipTriggers:",
|
|
620
|
-
(NSNumber *)SdkNilIfNSNull(sync),
|
|
621
|
-
(NSDictionary *)SdkNilIfNSNull(profileFields),
|
|
622
|
-
(NSDictionary *)SdkNilIfNSNull(customFields),
|
|
623
|
-
(NSArray *)SdkNilIfNSNull(cats),
|
|
624
|
-
(NSNumber *)SdkNilIfNSNull(replace),
|
|
625
|
-
(NSNumber *)SdkNilIfNSNull(skipTriggers));
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
- (void)pushUnSubscribe:(NSNumber *)sync
|
|
629
|
-
profileFields:(NSDictionary *)profileFields
|
|
630
|
-
customFields:(NSDictionary *)customFields
|
|
631
|
-
cats:(NSArray *)cats
|
|
632
|
-
replace:(NSNumber *)replace
|
|
633
|
-
skipTriggers:(NSNumber *)skipTriggers
|
|
634
|
-
{
|
|
635
|
-
id module = SdkAppModuleSharedInstance();
|
|
636
|
-
EnsureProvidersInstalled(module);
|
|
637
|
-
|
|
638
|
-
CallPushSubscription(module,
|
|
639
|
-
@"pushUnSubscribe:profileFields:customFields:cats:replace:skipTriggers:",
|
|
640
|
-
(NSNumber *)SdkNilIfNSNull(sync),
|
|
641
|
-
(NSDictionary *)SdkNilIfNSNull(profileFields),
|
|
642
|
-
(NSDictionary *)SdkNilIfNSNull(customFields),
|
|
643
|
-
(NSArray *)SdkNilIfNSNull(cats),
|
|
644
|
-
(NSNumber *)SdkNilIfNSNull(replace),
|
|
645
|
-
(NSNumber *)SdkNilIfNSNull(skipTriggers));
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
#pragma mark - MobileEvent (void) with subscription
|
|
649
|
-
|
|
650
|
-
#ifdef RCT_NEW_ARCH_ENABLED
|
|
651
|
-
|
|
652
|
-
- (void)mobileEvent:(NSString *)sid
|
|
653
|
-
eventName:(NSString *)eventName
|
|
654
|
-
sendMessageId:(NSString * _Nullable)sendMessageId
|
|
655
|
-
payload:(NSDictionary * _Nullable)payload
|
|
656
|
-
matching:(NSDictionary * _Nullable)matching
|
|
657
|
-
matchingType:(NSString * _Nullable)matchingType
|
|
658
|
-
profileFields:(NSDictionary * _Nullable)profileFields
|
|
659
|
-
subscription:(NSDictionary * _Nullable)subscription
|
|
660
|
-
utm:(JS::NativeSdk::UTM &)utm
|
|
661
|
-
{
|
|
662
|
-
id module = SdkAppModuleSharedInstance();
|
|
663
|
-
EnsureProvidersInstalled(module);
|
|
664
|
-
|
|
665
|
-
NSDictionary *utmDict = SdkConvertUTMToNSDictionary(utm);
|
|
666
|
-
|
|
667
|
-
CallMobileEvent(module,
|
|
668
|
-
(NSString *)SdkNilIfNSNull(sid),
|
|
669
|
-
(NSString *)SdkNilIfNSNull(eventName),
|
|
670
|
-
(NSString *)SdkNilIfNSNull(sendMessageId),
|
|
671
|
-
(NSDictionary *)SdkNilIfNSNull(payload),
|
|
672
|
-
(NSDictionary *)SdkNilIfNSNull(matching),
|
|
673
|
-
(NSString *)SdkNilIfNSNull(matchingType),
|
|
674
|
-
(NSDictionary *)SdkNilIfNSNull(profileFields),
|
|
675
|
-
(NSDictionary *)SdkNilIfNSNull(subscription),
|
|
676
|
-
(NSDictionary *)SdkNilIfNSNull(utmDict));
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
#else // OLD ARCH
|
|
680
|
-
|
|
681
|
-
- (void)mobileEvent:(NSString *)sid
|
|
682
|
-
eventName:(NSString *)eventName
|
|
683
|
-
sendMessageId:(NSString * _Nullable)sendMessageId
|
|
684
|
-
payload:(NSDictionary * _Nullable)payload
|
|
685
|
-
matching:(NSDictionary * _Nullable)matching
|
|
686
|
-
matchingType:(NSString * _Nullable)matchingType
|
|
687
|
-
profileFields:(NSDictionary * _Nullable)profileFields
|
|
688
|
-
subscription:(NSDictionary * _Nullable)subscription
|
|
689
|
-
utm:(NSDictionary * _Nullable)utm
|
|
690
|
-
{
|
|
691
|
-
id module = SdkAppModuleSharedInstance();
|
|
692
|
-
EnsureProvidersInstalled(module);
|
|
693
|
-
|
|
694
|
-
CallMobileEvent(module,
|
|
695
|
-
(NSString *)SdkNilIfNSNull(sid),
|
|
696
|
-
(NSString *)SdkNilIfNSNull(eventName),
|
|
697
|
-
(NSString *)SdkNilIfNSNull(sendMessageId),
|
|
698
|
-
(NSDictionary *)SdkNilIfNSNull(payload),
|
|
699
|
-
(NSDictionary *)SdkNilIfNSNull(matching),
|
|
700
|
-
(NSString *)SdkNilIfNSNull(matchingType),
|
|
701
|
-
(NSDictionary *)SdkNilIfNSNull(profileFields),
|
|
702
|
-
(NSDictionary *)SdkNilIfNSNull(subscription),
|
|
703
|
-
(NSDictionary *)SdkNilIfNSNull(utm));
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
#endif
|
|
707
|
-
|
|
708
|
-
#pragma mark - Promises
|
|
709
|
-
|
|
710
|
-
- (void)unSuspendPushSubscription:(RCTPromiseResolveBlock)resolve
|
|
711
|
-
reject:(RCTPromiseRejectBlock)reject
|
|
712
|
-
{
|
|
713
|
-
id module = SdkAppModuleSharedInstance();
|
|
714
|
-
EnsureProvidersInstalled(module);
|
|
715
|
-
CallPromise0Args(module, @"unSuspendPushSubscriptionWithResolver:rejecter:", resolve, reject);
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
- (void)getStatusOfLatestSubscription:(RCTPromiseResolveBlock)resolve
|
|
719
|
-
reject:(RCTPromiseRejectBlock)reject
|
|
720
|
-
{
|
|
721
|
-
id module = SdkAppModuleSharedInstance();
|
|
722
|
-
EnsureProvidersInstalled(module);
|
|
723
|
-
CallPromise0Args(module, @"getStatusOfLatestSubscriptionWithResolver:rejecter:", resolve, reject);
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
- (void)getStatusForCurrentSubscription:(RCTPromiseResolveBlock)resolve
|
|
727
|
-
reject:(RCTPromiseRejectBlock)reject
|
|
728
|
-
{
|
|
729
|
-
id module = SdkAppModuleSharedInstance();
|
|
730
|
-
EnsureProvidersInstalled(module);
|
|
731
|
-
CallPromise0Args(module, @"getStatusForCurrentSubscriptionWithResolver:rejecter:", resolve, reject);
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
- (void)getStatusOfLatestSubscriptionForProvider:(NSString * _Nullable)provider
|
|
735
|
-
resolve:(RCTPromiseResolveBlock)resolve
|
|
736
|
-
reject:(RCTPromiseRejectBlock)reject
|
|
737
|
-
{
|
|
738
|
-
id module = SdkAppModuleSharedInstance();
|
|
739
|
-
EnsureProvidersInstalled(module);
|
|
740
|
-
NSString *p = (NSString *)SdkNilIfNSNull(provider);
|
|
741
|
-
CallPromise1StringArg(module,
|
|
742
|
-
@"getStatusOfLatestSubscriptionForProviderWithProvider:resolver:rejecter:",
|
|
743
|
-
p,
|
|
744
|
-
resolve,
|
|
745
|
-
reject);
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
- (void)clear:(RCTPromiseResolveBlock)resolve
|
|
749
|
-
reject:(RCTPromiseRejectBlock)reject
|
|
750
|
-
{
|
|
751
|
-
id module = SdkAppModuleSharedInstance();
|
|
752
|
-
EnsureProvidersInstalled(module);
|
|
753
|
-
CallClear(module, resolve, reject);
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
#pragma mark - Push token API (ONLY getPushToken / setPushToken)
|
|
757
|
-
|
|
758
|
-
- (void)getPushToken:(RCTPromiseResolveBlock)resolve
|
|
759
|
-
reject:(RCTPromiseRejectBlock)reject
|
|
760
|
-
{
|
|
761
|
-
id module = SdkAppModuleSharedInstance();
|
|
762
|
-
if (!module) {
|
|
763
|
-
NSError *err = [NSError errorWithDomain:@"Sdk" code:1 userInfo:@{NSLocalizedDescriptionKey:@"SdkAppModule not found"}];
|
|
764
|
-
reject(@"SWIFT_MODULE_NOT_FOUND", @"SdkAppModule class not found", err);
|
|
765
|
-
return;
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
EnsureProvidersInstalled(module);
|
|
769
|
-
|
|
770
|
-
CallGetPushToken(module, ^(id _Nullable tokenObjC) {
|
|
771
|
-
if (!tokenObjC) { resolve((id)kCFNull); return; }
|
|
772
|
-
|
|
773
|
-
NSString *provider = nil;
|
|
774
|
-
NSString *token = nil;
|
|
775
|
-
|
|
776
|
-
@try {
|
|
777
|
-
provider = [tokenObjC valueForKey:@"provider"];
|
|
778
|
-
token = [tokenObjC valueForKey:@"token"];
|
|
779
|
-
} @catch (__unused NSException *e) {}
|
|
780
|
-
|
|
781
|
-
if (!provider && !token) { resolve((id)kCFNull); return; }
|
|
782
|
-
|
|
783
|
-
resolve(@{
|
|
784
|
-
@"provider": provider ?: (id)kCFNull,
|
|
785
|
-
@"token": token ?: (id)kCFNull
|
|
786
|
-
});
|
|
787
|
-
});
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
- (void)setPushToken:(NSString *)provider
|
|
791
|
-
token:(NSString * _Nullable)token
|
|
792
|
-
resolve:(RCTPromiseResolveBlock)resolve
|
|
793
|
-
reject:(RCTPromiseRejectBlock)reject
|
|
794
|
-
{
|
|
795
|
-
id module = SdkAppModuleSharedInstance();
|
|
796
|
-
if (!module) {
|
|
797
|
-
NSError *err = [NSError errorWithDomain:@"Sdk" code:1 userInfo:@{NSLocalizedDescriptionKey:@"SdkAppModule not found"}];
|
|
798
|
-
reject(@"SWIFT_MODULE_NOT_FOUND", @"SdkAppModule class not found", err);
|
|
799
|
-
return;
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
EnsureProvidersInstalled(module);
|
|
803
|
-
|
|
804
|
-
if (!provider || provider.length == 0) {
|
|
805
|
-
NSError *err = [NSError errorWithDomain:@"Sdk" code:4 userInfo:@{NSLocalizedDescriptionKey:@"Provider is empty"}];
|
|
806
|
-
reject(@"INVALID_PROVIDER", @"Provider is empty", err);
|
|
807
|
-
return;
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
CallSetPushToken(module, provider, token);
|
|
811
|
-
resolve((id)kCFNull);
|
|
812
|
-
}
|
|
813
|
-
|
|
814
|
-
#pragma mark - UserDefaults
|
|
815
|
-
|
|
816
|
-
- (void)setUserDefaultsValue:(NSString * _Nullable)suiteName
|
|
817
|
-
key:(NSString *)key
|
|
818
|
-
value:(NSString * _Nullable)value
|
|
819
|
-
{
|
|
820
|
-
id module = SdkAppModuleSharedInstance();
|
|
821
|
-
EnsureProvidersInstalled(module);
|
|
822
|
-
|
|
823
|
-
NSString *sn = (NSString *)SdkNilIfNSNull(suiteName);
|
|
824
|
-
NSString *k = (NSString *)SdkNilIfNSNull(key);
|
|
825
|
-
id v = SdkNilIfNSNull(value);
|
|
826
|
-
|
|
827
|
-
if (!module) return;
|
|
828
|
-
if (!k || k.length == 0) return;
|
|
829
|
-
|
|
830
|
-
if (![NSThread isMainThread]) {
|
|
831
|
-
dispatch_async(dispatch_get_main_queue(), ^{
|
|
832
|
-
CallSetUserDefaultsValue(module, sn, k, v);
|
|
833
|
-
});
|
|
834
|
-
return;
|
|
835
|
-
}
|
|
836
|
-
|
|
837
|
-
CallSetUserDefaultsValue(module, sn, k, v);
|
|
838
|
-
}
|
|
839
|
-
|
|
840
|
-
#pragma mark - Profile API
|
|
841
|
-
|
|
842
|
-
- (void)updateProfileFields:(NSDictionary * _Nullable)profileFields
|
|
843
|
-
skipTriggers:(NSNumber *)skipTriggers
|
|
844
|
-
{
|
|
845
|
-
id module = SdkAppModuleSharedInstance();
|
|
846
|
-
EnsureProvidersInstalled(module);
|
|
847
|
-
|
|
848
|
-
SEL sel = SdkSel(@"updateProfileFields:skipTriggers:");
|
|
849
|
-
if (!SdkResponds(module, sel)) return;
|
|
850
|
-
|
|
851
|
-
IMP imp = [module methodForSelector:sel];
|
|
852
|
-
if (!imp) return;
|
|
853
|
-
|
|
854
|
-
void (*func)(id, SEL, id, id) = (void (*)(id, SEL, id, id))imp;
|
|
855
|
-
func(module, sel, (NSDictionary *)SdkNilIfNSNull(profileFields), (NSNumber *)SdkNilIfNSNull(skipTriggers));
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
#pragma mark - Token management API
|
|
859
|
-
|
|
860
|
-
- (void)forcedTokenUpdate:(RCTPromiseResolveBlock)resolve
|
|
861
|
-
reject:(RCTPromiseRejectBlock)reject
|
|
862
|
-
{
|
|
863
|
-
id module = SdkAppModuleSharedInstance();
|
|
864
|
-
EnsureProvidersInstalled(module);
|
|
865
|
-
CallPromise0Args(module, @"forcedTokenUpdateWithResolver:rejecter:", resolve, reject);
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
- (void)deleteDeviceToken:(NSString *)provider
|
|
869
|
-
resolve:(RCTPromiseResolveBlock)resolve
|
|
870
|
-
reject:(RCTPromiseRejectBlock)reject
|
|
871
|
-
{
|
|
872
|
-
id module = SdkAppModuleSharedInstance();
|
|
873
|
-
EnsureProvidersInstalled(module);
|
|
874
|
-
CallPromise1StringArg(module, @"deleteDeviceTokenWithProvider:resolver:rejecter:", provider, resolve, reject);
|
|
875
|
-
}
|
|
876
|
-
|
|
877
|
-
- (void)changePushProviderPriorityList:(NSArray *)priorityList
|
|
878
|
-
resolve:(RCTPromiseResolveBlock)resolve
|
|
879
|
-
reject:(RCTPromiseRejectBlock)reject
|
|
880
|
-
{
|
|
881
|
-
id module = SdkAppModuleSharedInstance();
|
|
882
|
-
EnsureProvidersInstalled(module);
|
|
883
|
-
|
|
884
|
-
SEL sel = SdkSel(@"changePushProviderPriorityList:");
|
|
885
|
-
if (!SdkResponds(module, sel)) {
|
|
886
|
-
reject(@"ERR_METHOD_NOT_FOUND", @"changePushProviderPriorityList: not found", nil);
|
|
887
|
-
return;
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
IMP imp = [module methodForSelector:sel];
|
|
891
|
-
if (!imp) {
|
|
892
|
-
reject(@"ERR_METHOD_NOT_FOUND", @"changePushProviderPriorityList: not found", nil);
|
|
893
|
-
return;
|
|
894
|
-
}
|
|
895
|
-
|
|
896
|
-
void (*func)(id, SEL, id) = (void (*)(id, SEL, id))imp;
|
|
897
|
-
func(module, sel, priorityList ?: @[]);
|
|
898
|
-
resolve((id)kCFNull);
|
|
899
|
-
}
|
|
900
|
-
|
|
901
|
-
#pragma mark - PushReceiver helpers
|
|
902
|
-
|
|
903
|
-
- (NSNumber *)isAltcraftPush:(NSDictionary * _Nullable)message
|
|
904
|
-
{
|
|
905
|
-
id module = SdkAppModuleSharedInstance();
|
|
906
|
-
if (!module) return @NO;
|
|
907
|
-
|
|
908
|
-
SEL sel = SdkSel(@"isAltcraftPush:");
|
|
909
|
-
if (!SdkResponds(module, sel)) return @NO;
|
|
910
|
-
|
|
911
|
-
IMP imp = [module methodForSelector:sel];
|
|
912
|
-
if (!imp) return @NO;
|
|
913
|
-
|
|
914
|
-
BOOL (*func)(id, SEL, id) = (BOOL (*)(id, SEL, id))imp;
|
|
915
|
-
BOOL result = func(module, sel, (NSDictionary *)SdkNilIfNSNull(message));
|
|
916
|
-
return [NSNumber numberWithBool:result];
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
#pragma mark - Session unlock
|
|
920
|
-
|
|
921
|
-
- (void)unlockInitialOperationsInThisSession
|
|
922
|
-
{
|
|
923
|
-
id module = SdkAppModuleSharedInstance();
|
|
924
|
-
if (!module) return;
|
|
925
|
-
|
|
926
|
-
SEL sel = SdkSel(@"unlockInitialOperationsInThisSession");
|
|
927
|
-
if (!SdkResponds(module, sel)) return;
|
|
928
|
-
|
|
929
|
-
IMP imp = [module methodForSelector:sel];
|
|
930
|
-
if (!imp) return;
|
|
931
|
-
|
|
932
|
-
void (*func)(id, SEL) = (void (*)(id, SEL))imp;
|
|
933
|
-
func(module, sel);
|
|
934
|
-
}
|
|
935
|
-
|
|
936
|
-
#pragma mark - App Group
|
|
937
|
-
|
|
938
|
-
- (void)setAppGroup:(NSString * _Nullable)groupName
|
|
939
|
-
{
|
|
940
|
-
id module = SdkAppModuleSharedInstance();
|
|
941
|
-
if (!module) return;
|
|
942
|
-
|
|
943
|
-
SEL sel = SdkSel(@"setAppGroup:");
|
|
944
|
-
if (!SdkResponds(module, sel)) return;
|
|
945
|
-
|
|
946
|
-
IMP imp = [module methodForSelector:sel];
|
|
947
|
-
if (!imp) return;
|
|
948
|
-
|
|
949
|
-
void (*func)(id, SEL, id) = (void (*)(id, SEL, id))imp;
|
|
950
|
-
func(module, sel, (NSString *)SdkNilIfNSNull(groupName));
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
#pragma mark - iOS-only stubs (kept if present in spec / facade)
|
|
954
|
-
|
|
955
|
-
- (void)deliveryEvent:(NSDictionary * _Nullable)message
|
|
956
|
-
messageUID:(NSString * _Nullable)messageUID
|
|
957
|
-
{
|
|
958
|
-
(void)message;
|
|
959
|
-
(void)messageUID;
|
|
960
|
-
}
|
|
961
|
-
|
|
962
|
-
- (void)openEvent:(NSDictionary * _Nullable)message
|
|
963
|
-
messageUID:(NSString * _Nullable)messageUID
|
|
964
|
-
{
|
|
965
|
-
(void)message;
|
|
966
|
-
(void)messageUID;
|
|
967
|
-
}
|
|
968
|
-
|
|
969
|
-
- (void)requestNotificationPermission
|
|
970
|
-
{
|
|
971
|
-
}
|
|
972
|
-
|
|
973
|
-
- (void)takePush:(NSDictionary * _Nullable)message
|
|
974
|
-
{
|
|
975
|
-
(void)message;
|
|
976
|
-
}
|
|
977
|
-
|
|
978
|
-
@end
|
|
979
|
-
|