@altcraft/react-native-sdk 0.0.1 → 0.0.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/LICENSE +20 -20
- package/README.md +5 -2
- package/android/build.gradle +2 -3
- package/android/src/main/java/com/altcraft/sdk/SdkModule.kt +493 -896
- package/android/src/main/java/com/altcraft/sdk/utilities/Converter.kt +326 -0
- package/android/src/main/java/com/altcraft/sdk/utilities/Extension.kt +72 -0
- package/ios/Converter.swift +640 -0
- package/ios/Sdk.h +4 -3
- package/ios/Sdk.mm +124 -370
- package/ios/SdkModule.swift +436 -653
- package/lib/module/NativeSdk.js +35 -0
- package/lib/module/NativeSdk.js.map +1 -1
- package/lib/module/Utilities.js +94 -0
- package/lib/module/Utilities.js.map +1 -0
- package/lib/module/index.js +180 -419
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/NativeSdk.d.ts +117 -32
- package/lib/typescript/src/NativeSdk.d.ts.map +1 -1
- package/lib/typescript/src/Utilities.d.ts +15 -0
- package/lib/typescript/src/Utilities.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +113 -308
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/NativeSdk.ts +156 -46
- package/src/Utilities.ts +116 -0
- package/src/index.tsx +255 -483
- package/android/src/main/java/com/altcraft/sdk/interfaces/RnFCMProvider.kt +0 -27
- package/android/src/main/java/com/altcraft/sdk/interfaces/RnHMSProvider.kt +0 -32
- package/android/src/main/java/com/altcraft/sdk/interfaces/RnJWTProvider.kt +0 -21
- package/android/src/main/java/com/altcraft/sdk/interfaces/RnRustoreProvider.kt +0 -53
- package/ios/protocols/RNAPNSProvider.swift +0 -15
- package/ios/protocols/RNFCMProvider.swift +0 -24
- package/ios/protocols/RNHMSProvider.swift +0 -24
- package/ios/protocols/RNJWTProvider.swift +0 -15
package/ios/Sdk.mm
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
//
|
|
1
|
+
// Sdk.mm
|
|
2
|
+
|
|
2
3
|
#import "Sdk.h"
|
|
3
4
|
|
|
4
5
|
#ifdef RCT_NEW_ARCH_ENABLED
|
|
@@ -23,7 +24,6 @@
|
|
|
23
24
|
#if __has_include(<React/RCTCallableJSModules.h>)
|
|
24
25
|
#import <React/RCTCallableJSModules.h>
|
|
25
26
|
#else
|
|
26
|
-
/// Minimal protocol for calling JS from native when headers are not available.
|
|
27
27
|
@protocol RCTCallableJSModules <NSObject>
|
|
28
28
|
- (void)invokeModule:(NSString *)moduleName
|
|
29
29
|
method:(NSString *)methodName
|
|
@@ -32,12 +32,10 @@
|
|
|
32
32
|
#endif
|
|
33
33
|
|
|
34
34
|
#ifndef RCTPromiseResolveBlock
|
|
35
|
-
/// React Native promise resolver.
|
|
36
35
|
typedef void (^RCTPromiseResolveBlock)(id _Nullable result);
|
|
37
36
|
#endif
|
|
38
37
|
|
|
39
38
|
#ifndef RCTPromiseRejectBlock
|
|
40
|
-
/// React Native promise rejecter.
|
|
41
39
|
typedef void (^RCTPromiseRejectBlock)(NSString * _Nonnull code,
|
|
42
40
|
NSString * _Nullable message,
|
|
43
41
|
NSError * _Nullable error);
|
|
@@ -45,36 +43,30 @@ typedef void (^RCTPromiseRejectBlock)(NSString * _Nonnull code,
|
|
|
45
43
|
|
|
46
44
|
#pragma mark - Runtime helpers
|
|
47
45
|
|
|
48
|
-
/// Builds selector from string.
|
|
49
46
|
static SEL SdkSel(NSString *name) {
|
|
50
47
|
return NSSelectorFromString(name);
|
|
51
48
|
}
|
|
52
49
|
|
|
53
|
-
/// Returns YES if instance responds to selector.
|
|
54
50
|
static BOOL SdkResponds(id obj, SEL sel) {
|
|
55
51
|
return obj && sel && [obj respondsToSelector:sel];
|
|
56
52
|
}
|
|
57
53
|
|
|
58
|
-
/// Returns YES if class responds to selector.
|
|
59
54
|
static BOOL SdkClassResponds(Class cls, SEL sel) {
|
|
60
55
|
return cls && sel && [cls respondsToSelector:sel];
|
|
61
56
|
}
|
|
62
57
|
|
|
63
58
|
#pragma mark - NSNull -> nil
|
|
64
59
|
|
|
65
|
-
/// Converts NSNull / kCFNull to nil (keeps other values as-is).
|
|
66
60
|
static inline id SdkNilIfNSNull(id v) {
|
|
67
61
|
return (v == (id)kCFNull || [v isKindOfClass:[NSNull class]]) ? nil : v;
|
|
68
62
|
}
|
|
69
63
|
|
|
70
64
|
#pragma mark - Swift runtime bridge (no Sdk-Swift.h needed)
|
|
71
65
|
|
|
72
|
-
/// Returns SdkModule class if present (resolved by name at runtime).
|
|
73
66
|
static Class SdkAppModuleClass(void) {
|
|
74
67
|
Class cls = NSClassFromString(@"SdkModule");
|
|
75
68
|
|
|
76
69
|
#ifdef DEBUG
|
|
77
|
-
// Debug-only: attempt to discover module name with namespace suffix.
|
|
78
70
|
if (!cls) {
|
|
79
71
|
int count = objc_getClassList(NULL, 0);
|
|
80
72
|
if (count > 0) {
|
|
@@ -99,7 +91,6 @@ static Class SdkAppModuleClass(void) {
|
|
|
99
91
|
return cls;
|
|
100
92
|
}
|
|
101
93
|
|
|
102
|
-
/// Returns shared Swift module instance via +[SdkModule shared].
|
|
103
94
|
static id SdkAppModuleSharedInstance(void) {
|
|
104
95
|
Class cls = SdkAppModuleClass();
|
|
105
96
|
if (!cls) return nil;
|
|
@@ -114,7 +105,6 @@ static id SdkAppModuleSharedInstance(void) {
|
|
|
114
105
|
return func((id)cls, sel);
|
|
115
106
|
}
|
|
116
107
|
|
|
117
|
-
/// Ensures push providers are installed/configured inside Swift module.
|
|
118
108
|
static void EnsureProvidersInstalled(id instance) {
|
|
119
109
|
if (!instance) return;
|
|
120
110
|
|
|
@@ -128,49 +118,26 @@ static void EnsureProvidersInstalled(id instance) {
|
|
|
128
118
|
func(instance, sel);
|
|
129
119
|
}
|
|
130
120
|
|
|
131
|
-
|
|
132
|
-
static void CallSetToken(id instance, NSString *selectorName, NSString * _Nullable token) {
|
|
133
|
-
if (!instance) return;
|
|
121
|
+
#pragma mark - Swift calls (UserDefaults)
|
|
134
122
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (!imp) return;
|
|
140
|
-
|
|
141
|
-
void (*func)(id, SEL, id) = (void (*)(id, SEL, id))imp;
|
|
142
|
-
func(instance, sel, token);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/// Sets App Group name on Swift module.
|
|
146
|
-
static void CallSetAppGroup(id instance, NSString * _Nullable groupName) {
|
|
123
|
+
static void CallSetUserDefaultsValue(id instance,
|
|
124
|
+
NSString * _Nullable suiteName,
|
|
125
|
+
NSString *key,
|
|
126
|
+
id _Nullable value) {
|
|
147
127
|
if (!instance) return;
|
|
148
128
|
|
|
149
|
-
SEL sel = SdkSel(@"
|
|
129
|
+
SEL sel = SdkSel(@"setUserDefaultsValueWithSuiteName:key:value:");
|
|
150
130
|
if (!SdkResponds(instance, sel)) return;
|
|
151
131
|
|
|
152
132
|
IMP imp = [instance methodForSelector:sel];
|
|
153
133
|
if (!imp) return;
|
|
154
134
|
|
|
155
|
-
void (*func)(id, SEL, id) = (void (*)(id, SEL, id))imp;
|
|
156
|
-
func(instance, sel,
|
|
135
|
+
void (*func)(id, SEL, id, id, id) = (void (*)(id, SEL, id, id, id))imp;
|
|
136
|
+
func(instance, sel, suiteName, key, value);
|
|
157
137
|
}
|
|
158
138
|
|
|
159
|
-
|
|
160
|
-
static void CallDeleteDeviceToken(id instance, NSString * _Nullable provider, void (^completion)(BOOL ok)) {
|
|
161
|
-
if (!instance) { completion(NO); return; }
|
|
162
|
-
|
|
163
|
-
SEL sel = SdkSel(@"deleteDeviceTokenWithProvider:completion:");
|
|
164
|
-
if (!SdkResponds(instance, sel)) { completion(NO); return; }
|
|
139
|
+
#pragma mark - Push token API (ONLY getPushToken / setPushToken)
|
|
165
140
|
|
|
166
|
-
IMP imp = [instance methodForSelector:sel];
|
|
167
|
-
if (!imp) { completion(NO); return; }
|
|
168
|
-
|
|
169
|
-
void (*func)(id, SEL, id, id) = (void (*)(id, SEL, id, id))imp;
|
|
170
|
-
func(instance, sel, provider, completion);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/// Retrieves current push token from Swift module.
|
|
174
141
|
static void CallGetPushToken(id instance, void (^completion)(id _Nullable tokenObjC)) {
|
|
175
142
|
if (!instance) { completion(nil); return; }
|
|
176
143
|
|
|
@@ -184,35 +151,6 @@ static void CallGetPushToken(id instance, void (^completion)(id _Nullable tokenO
|
|
|
184
151
|
func(instance, sel, completion);
|
|
185
152
|
}
|
|
186
153
|
|
|
187
|
-
/// Forces token update on Swift module.
|
|
188
|
-
static void CallForcedTokenUpdate(id instance, void (^completion)(void)) {
|
|
189
|
-
if (!instance) { completion(); return; }
|
|
190
|
-
|
|
191
|
-
SEL sel = SdkSel(@"forcedTokenUpdateWithCompletion:");
|
|
192
|
-
if (!SdkResponds(instance, sel)) { completion(); return; }
|
|
193
|
-
|
|
194
|
-
IMP imp = [instance methodForSelector:sel];
|
|
195
|
-
if (!imp) { completion(); return; }
|
|
196
|
-
|
|
197
|
-
void (*func)(id, SEL, id) = (void (*)(id, SEL, id))imp;
|
|
198
|
-
func(instance, sel, completion);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/// Changes push provider priority list on Swift module.
|
|
202
|
-
static void CallChangeProviderPriorityList(id instance, NSArray * _Nullable list, void (^completion)(BOOL ok)) {
|
|
203
|
-
if (!instance) { completion(NO); return; }
|
|
204
|
-
|
|
205
|
-
SEL sel = SdkSel(@"changePushProviderPriorityListWithList:completion:");
|
|
206
|
-
if (!SdkResponds(instance, sel)) { completion(NO); return; }
|
|
207
|
-
|
|
208
|
-
IMP imp = [instance methodForSelector:sel];
|
|
209
|
-
if (!imp) { completion(NO); return; }
|
|
210
|
-
|
|
211
|
-
void (*func)(id, SEL, id, id) = (void (*)(id, SEL, id, id))imp;
|
|
212
|
-
func(instance, sel, list, completion);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/// Sets push token with provider on Swift module.
|
|
216
154
|
static void CallSetPushToken(id instance, NSString *provider, NSString * _Nullable token) {
|
|
217
155
|
if (!instance) return;
|
|
218
156
|
|
|
@@ -228,7 +166,6 @@ static void CallSetPushToken(id instance, NSString *provider, NSString * _Nullab
|
|
|
228
166
|
|
|
229
167
|
#pragma mark - Push subscription calls
|
|
230
168
|
|
|
231
|
-
/// Invokes subscription-related methods on Swift module.
|
|
232
169
|
static void CallPushSubscription(id instance,
|
|
233
170
|
NSString *selectorName,
|
|
234
171
|
NSNumber *sync,
|
|
@@ -251,9 +188,8 @@ static void CallPushSubscription(id instance,
|
|
|
251
188
|
func(instance, sel, sync, profileFields, customFields, cats, replace, skipTriggers);
|
|
252
189
|
}
|
|
253
190
|
|
|
254
|
-
#pragma mark - Mobile Event calls
|
|
191
|
+
#pragma mark - Mobile Event calls (with subscription param)
|
|
255
192
|
|
|
256
|
-
/// Sends mobile event to Swift module.
|
|
257
193
|
static void CallMobileEvent(id instance,
|
|
258
194
|
NSString *sid,
|
|
259
195
|
NSString *eventName,
|
|
@@ -261,24 +197,25 @@ static void CallMobileEvent(id instance,
|
|
|
261
197
|
NSDictionary * _Nullable payload,
|
|
262
198
|
NSDictionary * _Nullable matching,
|
|
263
199
|
NSString * _Nullable matchingType,
|
|
264
|
-
NSDictionary * _Nullable profileFields
|
|
200
|
+
NSDictionary * _Nullable profileFields,
|
|
201
|
+
NSDictionary * _Nullable subscription,
|
|
202
|
+
NSDictionary * _Nullable utm) {
|
|
265
203
|
if (!instance) return;
|
|
266
204
|
|
|
267
|
-
SEL sel = SdkSel(@"mobileEvent:eventName:sendMessageId:payload:matching:matchingType:profileFields:");
|
|
205
|
+
SEL sel = SdkSel(@"mobileEvent:eventName:sendMessageId:payload:matching:matchingType:profileFields:subscription:utm:");
|
|
268
206
|
if (!SdkResponds(instance, sel)) return;
|
|
269
207
|
|
|
270
208
|
IMP imp = [instance methodForSelector:sel];
|
|
271
209
|
if (!imp) return;
|
|
272
210
|
|
|
273
|
-
void (*func)(id, SEL, id, id, id, id, id, id, id) =
|
|
274
|
-
(void (*)(id, SEL, id, id, id, id, id, id, id))imp;
|
|
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;
|
|
275
213
|
|
|
276
|
-
func(instance, sel, sid, eventName, sendMessageId, payload, matching, matchingType, profileFields);
|
|
214
|
+
func(instance, sel, sid, eventName, sendMessageId, payload, matching, matchingType, profileFields, subscription, utm);
|
|
277
215
|
}
|
|
278
216
|
|
|
279
217
|
#pragma mark - Promise helpers
|
|
280
218
|
|
|
281
|
-
/// Calls a Swift method with signature (resolver, rejecter).
|
|
282
219
|
static void CallPromise0Args(id instance,
|
|
283
220
|
NSString *selectorName,
|
|
284
221
|
RCTPromiseResolveBlock resolve,
|
|
@@ -296,7 +233,6 @@ static void CallPromise0Args(id instance,
|
|
|
296
233
|
return;
|
|
297
234
|
}
|
|
298
235
|
|
|
299
|
-
// React Native expects promise calls on main thread.
|
|
300
236
|
if (![NSThread isMainThread]) {
|
|
301
237
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
302
238
|
CallPromise0Args(instance, selectorName, resolve, reject);
|
|
@@ -306,7 +242,6 @@ static void CallPromise0Args(id instance,
|
|
|
306
242
|
|
|
307
243
|
IMP imp = [instance methodForSelector:sel];
|
|
308
244
|
if (!imp) {
|
|
309
|
-
// Fallback for cases where methodForSelector returns NULL in mixed ObjC/Swift builds.
|
|
310
245
|
NSMethodSignature *sig = [instance methodSignatureForSelector:sel];
|
|
311
246
|
if (!sig) {
|
|
312
247
|
NSError *err = [NSError errorWithDomain:@"Sdk" code:20 userInfo:@{NSLocalizedDescriptionKey:@"No signature"}];
|
|
@@ -331,7 +266,6 @@ static void CallPromise0Args(id instance,
|
|
|
331
266
|
func(instance, sel, resolve, reject);
|
|
332
267
|
}
|
|
333
268
|
|
|
334
|
-
/// Calls a Swift method with signature (String?, resolver, rejecter).
|
|
335
269
|
static void CallPromise1StringArg(id instance,
|
|
336
270
|
NSString *selectorName,
|
|
337
271
|
NSString * _Nullable arg,
|
|
@@ -350,7 +284,6 @@ static void CallPromise1StringArg(id instance,
|
|
|
350
284
|
return;
|
|
351
285
|
}
|
|
352
286
|
|
|
353
|
-
// React Native expects promise calls on main thread.
|
|
354
287
|
if (![NSThread isMainThread]) {
|
|
355
288
|
NSString *a = arg;
|
|
356
289
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
@@ -389,7 +322,6 @@ static void CallPromise1StringArg(id instance,
|
|
|
389
322
|
|
|
390
323
|
#pragma mark - Initialize / Clear
|
|
391
324
|
|
|
392
|
-
/// Calls Swift initializer selector on the main thread.
|
|
393
325
|
static void CallInitializeBySelector(id instance,
|
|
394
326
|
SEL sel,
|
|
395
327
|
NSDictionary *config,
|
|
@@ -431,7 +363,6 @@ static void CallInitializeBySelector(id instance,
|
|
|
431
363
|
func(instance, sel, safeCfg, resolve, reject);
|
|
432
364
|
}
|
|
433
365
|
|
|
434
|
-
/// Initializes Swift module with config.
|
|
435
366
|
static void CallInitialize(id instance,
|
|
436
367
|
NSDictionary *config,
|
|
437
368
|
RCTPromiseResolveBlock resolve,
|
|
@@ -452,118 +383,12 @@ static void CallInitialize(id instance,
|
|
|
452
383
|
CallInitializeBySelector(instance, sel, config, resolve, reject);
|
|
453
384
|
}
|
|
454
385
|
|
|
455
|
-
/// Clears SDK state in Swift module.
|
|
456
386
|
static void CallClear(id instance,
|
|
457
387
|
RCTPromiseResolveBlock resolve,
|
|
458
388
|
RCTPromiseRejectBlock reject) {
|
|
459
389
|
CallPromise0Args(instance, @"clearWithResolver:rejecter:", resolve, reject);
|
|
460
390
|
}
|
|
461
391
|
|
|
462
|
-
#pragma mark - Events: Swift -> NotificationCenter -> ObjC++ -> JS
|
|
463
|
-
|
|
464
|
-
/// Notification name used by Swift layer to publish events.
|
|
465
|
-
static NSString * const SdkEventsNotificationName = @"AltcraftSdkEventNotification";
|
|
466
|
-
|
|
467
|
-
static id _Nullable gSdkEventsObserver = nil;
|
|
468
|
-
static id<RCTCallableJSModules> _Nullable gCallableJSModules = nil;
|
|
469
|
-
|
|
470
|
-
/// Returns callableJSModules from a module instance if present.
|
|
471
|
-
static id<RCTCallableJSModules> _Nullable SdkGetCallableFromModule(id moduleInstance) {
|
|
472
|
-
if (!moduleInstance) return nil;
|
|
473
|
-
|
|
474
|
-
SEL sel = SdkSel(@"callableJSModules");
|
|
475
|
-
if (![moduleInstance respondsToSelector:sel]) return nil;
|
|
476
|
-
|
|
477
|
-
id (*msgSend)(id, SEL) = (id (*)(id, SEL))objc_msgSend;
|
|
478
|
-
id v = msgSend(moduleInstance, sel);
|
|
479
|
-
return (id<RCTCallableJSModules>)v;
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
/// Returns bridge from a module instance if present (Old Arch).
|
|
483
|
-
static id _Nullable SdkGetBridgeAny(id moduleInstance) {
|
|
484
|
-
if (!moduleInstance) return nil;
|
|
485
|
-
|
|
486
|
-
SEL sel = SdkSel(@"bridge");
|
|
487
|
-
if (![moduleInstance respondsToSelector:sel]) return nil;
|
|
488
|
-
|
|
489
|
-
id (*msgSend)(id, SEL) = (id (*)(id, SEL))objc_msgSend;
|
|
490
|
-
return msgSend(moduleInstance, sel);
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
/// Checks if bridge supports enqueueing JS calls.
|
|
494
|
-
static BOOL SdkBridgeCanEnqueue(id bridgeObj) {
|
|
495
|
-
if (!bridgeObj) return NO;
|
|
496
|
-
|
|
497
|
-
SEL sel = SdkSel(@"enqueueJSCall:method:args:completion:");
|
|
498
|
-
return [bridgeObj respondsToSelector:sel];
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
/// Emits event using bridge enqueue (Old Arch).
|
|
502
|
-
static void SdkBridgeEnqueueEmit(id bridgeObj, NSDictionary *payload) {
|
|
503
|
-
SEL sel = SdkSel(@"enqueueJSCall:method:args:completion:");
|
|
504
|
-
if (![bridgeObj respondsToSelector:sel]) return;
|
|
505
|
-
|
|
506
|
-
NSArray *args = @[@"AltcraftSdkEvent", payload ?: @{}];
|
|
507
|
-
|
|
508
|
-
void (*func)(id, SEL, id, id, id, id) = (void (*)(id, SEL, id, id, id, id))objc_msgSend;
|
|
509
|
-
func(bridgeObj, sel, @"RCTDeviceEventEmitter", @"emit", args, (id)nil);
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
/// Emits event to JS via callableJSModules (preferred) or bridge enqueue.
|
|
513
|
-
static void SdkEmitEventToJS(id moduleInstance, NSDictionary *payload) {
|
|
514
|
-
NSDictionary *safePayload = (payload && [payload isKindOfClass:[NSDictionary class]]) ? payload : @{};
|
|
515
|
-
|
|
516
|
-
// 1) New Arch: callableJSModules.
|
|
517
|
-
id<RCTCallableJSModules> callable = gCallableJSModules;
|
|
518
|
-
if (!callable) {
|
|
519
|
-
callable = SdkGetCallableFromModule(moduleInstance);
|
|
520
|
-
if (callable) gCallableJSModules = callable;
|
|
521
|
-
}
|
|
522
|
-
if (callable) {
|
|
523
|
-
[callable invokeModule:@"RCTDeviceEventEmitter"
|
|
524
|
-
method:@"emit"
|
|
525
|
-
withArgs:@[@"AltcraftSdkEvent", safePayload]];
|
|
526
|
-
return;
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
// 2) Old Arch: bridge enqueueJSCall.
|
|
530
|
-
id bridgeObj = SdkGetBridgeAny(moduleInstance);
|
|
531
|
-
if (SdkBridgeCanEnqueue(bridgeObj)) {
|
|
532
|
-
SdkBridgeEnqueueEmit(bridgeObj, safePayload);
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
/// Installs NotificationCenter observer to forward events to JS.
|
|
537
|
-
static void SdkInstallEventsObserverIfNeeded(id moduleInstance) {
|
|
538
|
-
// Refresh callable cache if possible.
|
|
539
|
-
id<RCTCallableJSModules> callable = SdkGetCallableFromModule(moduleInstance);
|
|
540
|
-
if (callable) gCallableJSModules = callable;
|
|
541
|
-
|
|
542
|
-
if (gSdkEventsObserver != nil) return;
|
|
543
|
-
|
|
544
|
-
gSdkEventsObserver =
|
|
545
|
-
[[NSNotificationCenter defaultCenter] addObserverForName:SdkEventsNotificationName
|
|
546
|
-
object:nil
|
|
547
|
-
queue:[NSOperationQueue mainQueue]
|
|
548
|
-
usingBlock:^(NSNotification *note) {
|
|
549
|
-
NSDictionary *payload = note.userInfo;
|
|
550
|
-
|
|
551
|
-
// Debug visibility for event flow (safe to keep).
|
|
552
|
-
NSLog(@"[AltcraftSdk] event %@", payload);
|
|
553
|
-
|
|
554
|
-
SdkEmitEventToJS(moduleInstance, payload);
|
|
555
|
-
}];
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
/// Removes NotificationCenter observer.
|
|
559
|
-
static void SdkRemoveEventsObserverIfNeeded(void) {
|
|
560
|
-
if (!gSdkEventsObserver) return;
|
|
561
|
-
|
|
562
|
-
[[NSNotificationCenter defaultCenter] removeObserver:gSdkEventsObserver];
|
|
563
|
-
gSdkEventsObserver = nil;
|
|
564
|
-
gCallableJSModules = nil;
|
|
565
|
-
}
|
|
566
|
-
|
|
567
392
|
#pragma mark - Typed config -> NSDictionary (New Arch)
|
|
568
393
|
|
|
569
394
|
#ifdef RCT_NEW_ARCH_ENABLED
|
|
@@ -574,7 +399,6 @@ struct SdkIsStdOptional : std::false_type {};
|
|
|
574
399
|
template <typename T>
|
|
575
400
|
struct SdkIsStdOptional<std::optional<T>> : std::true_type {};
|
|
576
401
|
|
|
577
|
-
/// Converts NSString* / optional NSString* to NSString* or nil.
|
|
578
402
|
template <typename T>
|
|
579
403
|
static NSString *SdkGetStringOrNil(const T &v) {
|
|
580
404
|
using D = std::decay_t<T>;
|
|
@@ -587,7 +411,6 @@ static NSString *SdkGetStringOrNil(const T &v) {
|
|
|
587
411
|
}
|
|
588
412
|
}
|
|
589
413
|
|
|
590
|
-
/// Converts bool / optional bool to NSNumber* or nil.
|
|
591
414
|
template <typename T>
|
|
592
415
|
static NSNumber *SdkGetBoolNumberOrNil(const T &v) {
|
|
593
416
|
using D = std::decay_t<T>;
|
|
@@ -602,7 +425,6 @@ static NSNumber *SdkGetBoolNumberOrNil(const T &v) {
|
|
|
602
425
|
|
|
603
426
|
#import <limits.h>
|
|
604
427
|
|
|
605
|
-
/// Converts LazyVector<NSString*> to NSArray (capped to INT_MAX).
|
|
606
428
|
static NSArray *SdkLazyVectorToNSArray(const facebook::react::LazyVector<NSString *> &vec) {
|
|
607
429
|
const size_t n = vec.size();
|
|
608
430
|
const size_t capped = (n > (size_t)INT_MAX) ? (size_t)INT_MAX : n;
|
|
@@ -616,7 +438,6 @@ static NSArray *SdkLazyVectorToNSArray(const facebook::react::LazyVector<NSStrin
|
|
|
616
438
|
return arr;
|
|
617
439
|
}
|
|
618
440
|
|
|
619
|
-
/// Converts LazyVector / optional LazyVector to NSArray* or nil.
|
|
620
441
|
template <typename T>
|
|
621
442
|
static NSArray *SdkGetStringArrayOrNil(const T &v) {
|
|
622
443
|
using D = std::decay_t<T>;
|
|
@@ -629,7 +450,6 @@ static NSArray *SdkGetStringArrayOrNil(const T &v) {
|
|
|
629
450
|
}
|
|
630
451
|
}
|
|
631
452
|
|
|
632
|
-
/// Converts appInfo struct to NSDictionary* or nil.
|
|
633
453
|
template <typename T>
|
|
634
454
|
static NSDictionary *SdkGetAppInfoDictOrNil(const T &v) {
|
|
635
455
|
using D = std::decay_t<T>;
|
|
@@ -654,7 +474,6 @@ static NSDictionary *SdkGetAppInfoDictOrNil(const T &v) {
|
|
|
654
474
|
}
|
|
655
475
|
}
|
|
656
476
|
|
|
657
|
-
/// Converts typed RN config to NSDictionary for Swift module.
|
|
658
477
|
static NSDictionary *SdkConvertAltcraftConfigToNSDictionary(JS::NativeSdk::AltcraftConfig &cfg) {
|
|
659
478
|
NSString *apiUrl = cfg.apiUrl();
|
|
660
479
|
NSString *rToken = SdkGetStringOrNil(cfg.rToken());
|
|
@@ -671,6 +490,35 @@ static NSDictionary *SdkConvertAltcraftConfigToNSDictionary(JS::NativeSdk::Altcr
|
|
|
671
490
|
return dict;
|
|
672
491
|
}
|
|
673
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
|
+
|
|
674
522
|
#endif // RCT_NEW_ARCH_ENABLED
|
|
675
523
|
|
|
676
524
|
#pragma mark - Module implementation
|
|
@@ -678,7 +526,6 @@ static NSDictionary *SdkConvertAltcraftConfigToNSDictionary(JS::NativeSdk::Altcr
|
|
|
678
526
|
@implementation Sdk
|
|
679
527
|
|
|
680
528
|
#ifdef RCT_NEW_ARCH_ENABLED
|
|
681
|
-
/// Returns TurboModule instance for New Architecture.
|
|
682
529
|
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
683
530
|
(const facebook::react::ObjCTurboModule::InitParams &)params
|
|
684
531
|
{
|
|
@@ -686,11 +533,9 @@ static NSDictionary *SdkConvertAltcraftConfigToNSDictionary(JS::NativeSdk::Altcr
|
|
|
686
533
|
}
|
|
687
534
|
#endif // RCT_NEW_ARCH_ENABLED
|
|
688
535
|
|
|
689
|
-
/// React Native module name.
|
|
690
536
|
+ (NSString *)moduleName { return @"Sdk"; }
|
|
691
537
|
|
|
692
538
|
#ifdef RCT_NEW_ARCH_ENABLED
|
|
693
|
-
/// Initializes SDK using typed config (New Architecture).
|
|
694
539
|
- (void)initialize:(JS::NativeSdk::AltcraftConfig &)config
|
|
695
540
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
696
541
|
reject:(RCTPromiseRejectBlock)reject
|
|
@@ -703,21 +548,13 @@ static NSDictionary *SdkConvertAltcraftConfigToNSDictionary(JS::NativeSdk::Altcr
|
|
|
703
548
|
}
|
|
704
549
|
#endif // RCT_NEW_ARCH_ENABLED
|
|
705
550
|
|
|
706
|
-
/// Required by RN event emitter API (no-op).
|
|
707
551
|
- (void)addListener:(NSString *)eventName { (void)eventName; }
|
|
708
|
-
|
|
709
|
-
/// Required by RN event emitter API (no-op).
|
|
710
552
|
- (void)removeListeners:(double)count { (void)count; }
|
|
711
553
|
|
|
712
|
-
#pragma mark - Events API
|
|
554
|
+
#pragma mark - Events API (Swift emits; ObjC++ only forwards method calls)
|
|
713
555
|
|
|
714
|
-
/// Subscribes to SDK events and forwards them to JS.
|
|
715
556
|
- (void)subscribeToEvents
|
|
716
557
|
{
|
|
717
|
-
// Install observer and keep emitting to JS.
|
|
718
|
-
SdkInstallEventsObserverIfNeeded(self);
|
|
719
|
-
|
|
720
|
-
// Ask Swift to subscribe and start posting notifications.
|
|
721
558
|
id module = SdkAppModuleSharedInstance();
|
|
722
559
|
EnsureProvidersInstalled(module);
|
|
723
560
|
|
|
@@ -731,83 +568,23 @@ static NSDictionary *SdkConvertAltcraftConfigToNSDictionary(JS::NativeSdk::Altcr
|
|
|
731
568
|
func(module, sel);
|
|
732
569
|
}
|
|
733
570
|
|
|
734
|
-
/// Unsubscribes from SDK events and stops forwarding to JS.
|
|
735
571
|
- (void)unsubscribeFromEvent
|
|
736
572
|
{
|
|
737
573
|
id module = SdkAppModuleSharedInstance();
|
|
738
574
|
EnsureProvidersInstalled(module);
|
|
739
575
|
|
|
740
576
|
SEL sel = SdkSel(@"unsubscribeFromEvent");
|
|
741
|
-
if (SdkResponds(module, sel))
|
|
742
|
-
IMP imp = [module methodForSelector:sel];
|
|
743
|
-
if (imp) {
|
|
744
|
-
void (*func)(id, SEL) = (void (*)(id, SEL))imp;
|
|
745
|
-
func(module, sel);
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
SdkRemoveEventsObserverIfNeeded();
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
#pragma mark - Common (JWT / AppGroup)
|
|
753
|
-
|
|
754
|
-
/// Sets JWT used by SDK requests.
|
|
755
|
-
- (void)setJwt:(NSString * _Nullable)token {
|
|
756
|
-
id module = SdkAppModuleSharedInstance();
|
|
757
|
-
CallSetToken(module, @"setJWT:", token);
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
/// Sets App Group name for shared storage.
|
|
761
|
-
- (void)setAppGroup:(NSString * _Nullable)groupName
|
|
762
|
-
resolve:(RCTPromiseResolveBlock)resolve
|
|
763
|
-
reject:(RCTPromiseRejectBlock)reject
|
|
764
|
-
{
|
|
765
|
-
id module = SdkAppModuleSharedInstance();
|
|
766
|
-
if (!module) {
|
|
767
|
-
NSError *err = [NSError errorWithDomain:@"Sdk" code:1 userInfo:@{NSLocalizedDescriptionKey:@"SdkAppModule not found"}];
|
|
768
|
-
reject(@"SWIFT_MODULE_NOT_FOUND", @"SdkAppModule class not found", err);
|
|
769
|
-
return;
|
|
770
|
-
}
|
|
771
|
-
|
|
772
|
-
CallSetAppGroup(module, groupName);
|
|
773
|
-
resolve((id)kCFNull);
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
#pragma mark - Platform-specific tokens
|
|
777
|
-
|
|
778
|
-
/// Android-only API stub (no-op on iOS).
|
|
779
|
-
- (void)setAndroidFcmToken:(NSString * _Nullable)token { (void)token; }
|
|
780
|
-
|
|
781
|
-
/// Android-only API stub (no-op on iOS).
|
|
782
|
-
- (void)setAndroidHmsToken:(NSString * _Nullable)token { (void)token; }
|
|
783
|
-
|
|
784
|
-
/// Sets iOS FCM token in Swift module.
|
|
785
|
-
- (void)setIosFcmToken:(NSString * _Nullable)token {
|
|
786
|
-
id module = SdkAppModuleSharedInstance();
|
|
787
|
-
EnsureProvidersInstalled(module);
|
|
788
|
-
CallSetToken(module, @"setFCM:", token);
|
|
789
|
-
}
|
|
577
|
+
if (!SdkResponds(module, sel)) return;
|
|
790
578
|
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
id module = SdkAppModuleSharedInstance();
|
|
794
|
-
EnsureProvidersInstalled(module);
|
|
795
|
-
CallSetToken(module, @"setHMS:", token);
|
|
796
|
-
}
|
|
579
|
+
IMP imp = [module methodForSelector:sel];
|
|
580
|
+
if (!imp) return;
|
|
797
581
|
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
id module = SdkAppModuleSharedInstance();
|
|
801
|
-
EnsureProvidersInstalled(module);
|
|
802
|
-
CallSetToken(module, @"setAPNS:", token);
|
|
582
|
+
void (*func)(id, SEL) = (void (*)(id, SEL))imp;
|
|
583
|
+
func(module, sel);
|
|
803
584
|
}
|
|
804
585
|
|
|
805
|
-
/// RuStore-only API stub (no-op on iOS).
|
|
806
|
-
- (void)setRustoreToken:(NSString * _Nullable)token { (void)token; }
|
|
807
|
-
|
|
808
586
|
#pragma mark - Subscription (void)
|
|
809
587
|
|
|
810
|
-
/// Subscribes device for push notifications.
|
|
811
588
|
- (void)pushSubscribe:(NSNumber *)sync
|
|
812
589
|
profileFields:(NSDictionary *)profileFields
|
|
813
590
|
customFields:(NSDictionary *)customFields
|
|
@@ -828,7 +605,6 @@ static NSDictionary *SdkConvertAltcraftConfigToNSDictionary(JS::NativeSdk::Altcr
|
|
|
828
605
|
(NSNumber *)SdkNilIfNSNull(skipTriggers));
|
|
829
606
|
}
|
|
830
607
|
|
|
831
|
-
/// Suspends push subscription.
|
|
832
608
|
- (void)pushSuspend:(NSNumber *)sync
|
|
833
609
|
profileFields:(NSDictionary *)profileFields
|
|
834
610
|
customFields:(NSDictionary *)customFields
|
|
@@ -849,7 +625,6 @@ static NSDictionary *SdkConvertAltcraftConfigToNSDictionary(JS::NativeSdk::Altcr
|
|
|
849
625
|
(NSNumber *)SdkNilIfNSNull(skipTriggers));
|
|
850
626
|
}
|
|
851
627
|
|
|
852
|
-
/// Unsubscribes device from push notifications.
|
|
853
628
|
- (void)pushUnSubscribe:(NSNumber *)sync
|
|
854
629
|
profileFields:(NSDictionary *)profileFields
|
|
855
630
|
customFields:(NSDictionary *)customFields
|
|
@@ -870,16 +645,48 @@ static NSDictionary *SdkConvertAltcraftConfigToNSDictionary(JS::NativeSdk::Altcr
|
|
|
870
645
|
(NSNumber *)SdkNilIfNSNull(skipTriggers));
|
|
871
646
|
}
|
|
872
647
|
|
|
873
|
-
#pragma mark - MobileEvent (void)
|
|
648
|
+
#pragma mark - MobileEvent (void) with subscription
|
|
649
|
+
|
|
650
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
874
651
|
|
|
875
|
-
/// Sends a custom mobile event to backend.
|
|
876
652
|
- (void)mobileEvent:(NSString *)sid
|
|
877
653
|
eventName:(NSString *)eventName
|
|
878
654
|
sendMessageId:(NSString * _Nullable)sendMessageId
|
|
879
|
-
payload:(NSDictionary *)payload
|
|
880
|
-
matching:(NSDictionary *)matching
|
|
655
|
+
payload:(NSDictionary * _Nullable)payload
|
|
656
|
+
matching:(NSDictionary * _Nullable)matching
|
|
881
657
|
matchingType:(NSString * _Nullable)matchingType
|
|
882
|
-
profileFields:(NSDictionary *)profileFields
|
|
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
|
|
883
690
|
{
|
|
884
691
|
id module = SdkAppModuleSharedInstance();
|
|
885
692
|
EnsureProvidersInstalled(module);
|
|
@@ -891,12 +698,15 @@ static NSDictionary *SdkConvertAltcraftConfigToNSDictionary(JS::NativeSdk::Altcr
|
|
|
891
698
|
(NSDictionary *)SdkNilIfNSNull(payload),
|
|
892
699
|
(NSDictionary *)SdkNilIfNSNull(matching),
|
|
893
700
|
(NSString *)SdkNilIfNSNull(matchingType),
|
|
894
|
-
(NSDictionary *)SdkNilIfNSNull(profileFields)
|
|
701
|
+
(NSDictionary *)SdkNilIfNSNull(profileFields),
|
|
702
|
+
(NSDictionary *)SdkNilIfNSNull(subscription),
|
|
703
|
+
(NSDictionary *)SdkNilIfNSNull(utm));
|
|
895
704
|
}
|
|
896
705
|
|
|
706
|
+
#endif
|
|
707
|
+
|
|
897
708
|
#pragma mark - Promises
|
|
898
709
|
|
|
899
|
-
/// Unsuspends current push subscription.
|
|
900
710
|
- (void)unSuspendPushSubscription:(RCTPromiseResolveBlock)resolve
|
|
901
711
|
reject:(RCTPromiseRejectBlock)reject
|
|
902
712
|
{
|
|
@@ -905,7 +715,6 @@ static NSDictionary *SdkConvertAltcraftConfigToNSDictionary(JS::NativeSdk::Altcr
|
|
|
905
715
|
CallPromise0Args(module, @"unSuspendPushSubscriptionWithResolver:rejecter:", resolve, reject);
|
|
906
716
|
}
|
|
907
717
|
|
|
908
|
-
/// Returns status of latest subscription attempt.
|
|
909
718
|
- (void)getStatusOfLatestSubscription:(RCTPromiseResolveBlock)resolve
|
|
910
719
|
reject:(RCTPromiseRejectBlock)reject
|
|
911
720
|
{
|
|
@@ -914,7 +723,6 @@ static NSDictionary *SdkConvertAltcraftConfigToNSDictionary(JS::NativeSdk::Altcr
|
|
|
914
723
|
CallPromise0Args(module, @"getStatusOfLatestSubscriptionWithResolver:rejecter:", resolve, reject);
|
|
915
724
|
}
|
|
916
725
|
|
|
917
|
-
/// Returns current subscription status.
|
|
918
726
|
- (void)getStatusForCurrentSubscription:(RCTPromiseResolveBlock)resolve
|
|
919
727
|
reject:(RCTPromiseRejectBlock)reject
|
|
920
728
|
{
|
|
@@ -923,7 +731,6 @@ static NSDictionary *SdkConvertAltcraftConfigToNSDictionary(JS::NativeSdk::Altcr
|
|
|
923
731
|
CallPromise0Args(module, @"getStatusForCurrentSubscriptionWithResolver:rejecter:", resolve, reject);
|
|
924
732
|
}
|
|
925
733
|
|
|
926
|
-
/// Returns status of latest subscription for a specific provider.
|
|
927
734
|
- (void)getStatusOfLatestSubscriptionForProvider:(NSString * _Nullable)provider
|
|
928
735
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
929
736
|
reject:(RCTPromiseRejectBlock)reject
|
|
@@ -938,7 +745,6 @@ static NSDictionary *SdkConvertAltcraftConfigToNSDictionary(JS::NativeSdk::Altcr
|
|
|
938
745
|
reject);
|
|
939
746
|
}
|
|
940
747
|
|
|
941
|
-
/// Clears SDK state (tokens, cached values, etc).
|
|
942
748
|
- (void)clear:(RCTPromiseResolveBlock)resolve
|
|
943
749
|
reject:(RCTPromiseRejectBlock)reject
|
|
944
750
|
{
|
|
@@ -947,7 +753,8 @@ static NSDictionary *SdkConvertAltcraftConfigToNSDictionary(JS::NativeSdk::Altcr
|
|
|
947
753
|
CallClear(module, resolve, reject);
|
|
948
754
|
}
|
|
949
755
|
|
|
950
|
-
|
|
756
|
+
#pragma mark - Push token API (ONLY getPushToken / setPushToken)
|
|
757
|
+
|
|
951
758
|
- (void)getPushToken:(RCTPromiseResolveBlock)resolve
|
|
952
759
|
reject:(RCTPromiseRejectBlock)reject
|
|
953
760
|
{
|
|
@@ -980,10 +787,10 @@ static NSDictionary *SdkConvertAltcraftConfigToNSDictionary(JS::NativeSdk::Altcr
|
|
|
980
787
|
});
|
|
981
788
|
}
|
|
982
789
|
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
790
|
+
- (void)setPushToken:(NSString *)provider
|
|
791
|
+
token:(NSString * _Nullable)token
|
|
792
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
793
|
+
reject:(RCTPromiseRejectBlock)reject
|
|
987
794
|
{
|
|
988
795
|
id module = SdkAppModuleSharedInstance();
|
|
989
796
|
if (!module) {
|
|
@@ -994,119 +801,66 @@ static NSDictionary *SdkConvertAltcraftConfigToNSDictionary(JS::NativeSdk::Altcr
|
|
|
994
801
|
|
|
995
802
|
EnsureProvidersInstalled(module);
|
|
996
803
|
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
NSError *err = [NSError errorWithDomain:@"Sdk" code:2 userInfo:@{NSLocalizedDescriptionKey:@"Unknown provider"}];
|
|
1001
|
-
reject(@"INVALID_PROVIDER", @"Unknown provider for deleteDeviceToken", err);
|
|
1002
|
-
}
|
|
1003
|
-
});
|
|
1004
|
-
}
|
|
1005
|
-
|
|
1006
|
-
/// Forces push token update.
|
|
1007
|
-
- (void)forcedTokenUpdate:(RCTPromiseResolveBlock)resolve
|
|
1008
|
-
reject:(RCTPromiseRejectBlock)reject
|
|
1009
|
-
{
|
|
1010
|
-
id module = SdkAppModuleSharedInstance();
|
|
1011
|
-
if (!module) {
|
|
1012
|
-
NSError *err = [NSError errorWithDomain:@"Sdk" code:1 userInfo:@{NSLocalizedDescriptionKey:@"SdkAppModule not found"}];
|
|
1013
|
-
reject(@"SWIFT_MODULE_NOT_FOUND", @"SdkAppModule class not found", err);
|
|
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);
|
|
1014
807
|
return;
|
|
1015
808
|
}
|
|
1016
809
|
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
CallForcedTokenUpdate(module, ^{
|
|
1020
|
-
resolve((id)kCFNull);
|
|
1021
|
-
});
|
|
810
|
+
CallSetPushToken(module, provider, token);
|
|
811
|
+
resolve((id)kCFNull);
|
|
1022
812
|
}
|
|
1023
813
|
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
814
|
+
#pragma mark - UserDefaults
|
|
815
|
+
|
|
816
|
+
- (void)setUserDefaultsValue:(NSString * _Nullable)suiteName
|
|
817
|
+
key:(NSString *)key
|
|
818
|
+
value:(NSString * _Nullable)value
|
|
1028
819
|
{
|
|
1029
820
|
id module = SdkAppModuleSharedInstance();
|
|
1030
|
-
if (!module) {
|
|
1031
|
-
NSError *err = [NSError errorWithDomain:@"Sdk" code:1 userInfo:@{NSLocalizedDescriptionKey:@"SdkAppModule not found"}];
|
|
1032
|
-
reject(@"SWIFT_MODULE_NOT_FOUND", @"SdkAppModule class not found", err);
|
|
1033
|
-
return;
|
|
1034
|
-
}
|
|
1035
|
-
|
|
1036
821
|
EnsureProvidersInstalled(module);
|
|
1037
822
|
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
else {
|
|
1042
|
-
NSError *err = [NSError errorWithDomain:@"Sdk" code:3 userInfo:@{NSLocalizedDescriptionKey:@"Change priority failed"}];
|
|
1043
|
-
reject(@"CHANGE_PRIORITY_FAILED", @"Failed to change provider priority list", err);
|
|
1044
|
-
}
|
|
1045
|
-
});
|
|
1046
|
-
}
|
|
823
|
+
NSString *sn = (NSString *)SdkNilIfNSNull(suiteName);
|
|
824
|
+
NSString *k = (NSString *)SdkNilIfNSNull(key);
|
|
825
|
+
id v = SdkNilIfNSNull(value);
|
|
1047
826
|
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
token:(NSString * _Nullable)token
|
|
1051
|
-
resolve:(RCTPromiseResolveBlock)resolve
|
|
1052
|
-
reject:(RCTPromiseRejectBlock)reject
|
|
1053
|
-
{
|
|
1054
|
-
id module = SdkAppModuleSharedInstance();
|
|
1055
|
-
if (!module) {
|
|
1056
|
-
NSError *err = [NSError errorWithDomain:@"Sdk" code:1 userInfo:@{NSLocalizedDescriptionKey:@"SdkAppModule not found"}];
|
|
1057
|
-
reject(@"SWIFT_MODULE_NOT_FOUND", @"SdkAppModule class not found", err);
|
|
1058
|
-
return;
|
|
1059
|
-
}
|
|
1060
|
-
|
|
1061
|
-
EnsureProvidersInstalled(module);
|
|
827
|
+
if (!module) return;
|
|
828
|
+
if (!k || k.length == 0) return;
|
|
1062
829
|
|
|
1063
|
-
if (!
|
|
1064
|
-
|
|
1065
|
-
|
|
830
|
+
if (![NSThread isMainThread]) {
|
|
831
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
832
|
+
CallSetUserDefaultsValue(module, sn, k, v);
|
|
833
|
+
});
|
|
1066
834
|
return;
|
|
1067
835
|
}
|
|
1068
836
|
|
|
1069
|
-
|
|
1070
|
-
resolve((id)kCFNull);
|
|
837
|
+
CallSetUserDefaultsValue(module, sn, k, v);
|
|
1071
838
|
}
|
|
1072
839
|
|
|
1073
|
-
#pragma mark - iOS-only stubs (
|
|
840
|
+
#pragma mark - iOS-only stubs (kept if present in spec / facade)
|
|
1074
841
|
|
|
1075
|
-
/// iOS stub: delivery tracking is handled by server/other platforms.
|
|
1076
842
|
- (void)deliveryEvent:(NSDictionary * _Nullable)message
|
|
1077
843
|
messageUID:(NSString * _Nullable)messageUID
|
|
1078
844
|
{
|
|
1079
845
|
(void)message;
|
|
1080
846
|
(void)messageUID;
|
|
1081
|
-
// Intentionally not implemented on iOS.
|
|
1082
847
|
}
|
|
1083
848
|
|
|
1084
|
-
/// iOS stub: open tracking is handled by OS / deep-link flow.
|
|
1085
849
|
- (void)openEvent:(NSDictionary * _Nullable)message
|
|
1086
850
|
messageUID:(NSString * _Nullable)messageUID
|
|
1087
851
|
{
|
|
1088
852
|
(void)message;
|
|
1089
853
|
(void)messageUID;
|
|
1090
|
-
// Intentionally not implemented on iOS.
|
|
1091
|
-
}
|
|
1092
|
-
|
|
1093
|
-
/// iOS stub: retry control is managed in Swift layer / system scheduling.
|
|
1094
|
-
- (void)reinitializeRetryControlInThisSession
|
|
1095
|
-
{
|
|
1096
|
-
// Intentionally not implemented on iOS.
|
|
1097
854
|
}
|
|
1098
855
|
|
|
1099
|
-
/// iOS stub: permission prompt should be initiated by the host app UI.
|
|
1100
856
|
- (void)requestNotificationPermission
|
|
1101
857
|
{
|
|
1102
|
-
// Intentionally not implemented on iOS.
|
|
1103
858
|
}
|
|
1104
859
|
|
|
1105
|
-
/// iOS stub: push handling is done via AppDelegate / UNUserNotificationCenter callbacks.
|
|
1106
860
|
- (void)takePush:(NSDictionary * _Nullable)message
|
|
1107
861
|
{
|
|
1108
862
|
(void)message;
|
|
1109
|
-
// Intentionally not implemented on iOS.
|
|
1110
863
|
}
|
|
1111
864
|
|
|
1112
865
|
@end
|
|
866
|
+
|