@layers/react-native 0.2.0-alpha.4 → 0.2.0-alpha.6

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.
@@ -89,9 +89,8 @@ class LayersSKAN: NSObject {
89
89
  return
90
90
  }
91
91
 
92
- if #available(iOS 15.4, *) {
93
- // Use SKAN 3.0 API with completion handler
94
- SKAdNetwork.updateConversionValue(intValue) { error in
92
+ if #available(iOS 14.0, *) {
93
+ LayersSKANCompat.updateConversionValue(intValue) { error in
95
94
  if let error = error {
96
95
  print("[Layers SKAN] Error updating conversion value: \(error.localizedDescription)")
97
96
  reject("UPDATE_FAILED", error.localizedDescription, error)
@@ -101,12 +100,6 @@ class LayersSKAN: NSObject {
101
100
  resolve(nil)
102
101
  }
103
102
  }
104
- } else if #available(iOS 14.0, *) {
105
- // Use SKAN 2.x API (no completion handler)
106
- SKAdNetwork.updateConversionValue(intValue)
107
- conversionValue = intValue
108
- print("[Layers SKAN] Conversion value updated to: \(intValue)")
109
- resolve(nil)
110
103
  }
111
104
  }
112
105
 
@@ -121,47 +114,28 @@ class LayersSKAN: NSObject {
121
114
  return
122
115
  #endif
123
116
 
124
- guard #available(iOS 16.1, *) else {
125
- // Fallback to SKAN 3.0 API
126
- updateConversionValue(value, resolver: resolve, rejecter: reject)
127
- return
128
- }
129
-
130
117
  let intValue = value.intValue
131
118
  guard intValue >= 0 && intValue <= 63 else {
132
119
  reject("INVALID_VALUE", "Fine conversion value must be 0-63", nil)
133
120
  return
134
121
  }
135
122
 
136
- // Map coarse value string to enum
137
- let coarse: SKAdNetwork.CoarseConversionValue?
138
- if let coarseStr = coarseValue {
139
- switch coarseStr.lowercased() {
140
- case "low":
141
- coarse = .low
142
- case "medium":
143
- coarse = .medium
144
- case "high":
145
- coarse = .high
146
- default:
147
- coarse = nil
148
- }
149
- } else {
150
- coarse = nil
151
- }
152
-
123
+ let coarseStr = coarseValue?.lowercased()
153
124
  let lock = lockWindow?.boolValue ?? false
154
- let coarseValueOrDefault = coarse ?? .low // Default to .low if not specified
155
125
 
156
- SKAdNetwork.updatePostbackConversionValue(intValue, coarseValue: coarseValueOrDefault, lockWindow: lock) { error in
157
- if let error = error {
158
- print("[Layers SKAN] Error updating postback: \(error.localizedDescription)")
159
- reject("UPDATE_FAILED", error.localizedDescription, error)
160
- } else {
161
- self.conversionValue = intValue
162
- print("[Layers SKAN] Postback updated: value=\(intValue), coarse=\(coarseValue ?? "nil"), lock=\(lock)")
163
- resolve(nil)
126
+ if #available(iOS 14.0, *) {
127
+ LayersSKANCompat.updatePostbackConversionValue(intValue, coarseString: coarseStr, lockWindow: lock) { error in
128
+ if let error = error {
129
+ print("[Layers SKAN] Error updating postback: \(error.localizedDescription)")
130
+ reject("UPDATE_FAILED", error.localizedDescription, error)
131
+ } else {
132
+ self.conversionValue = intValue
133
+ print("[Layers SKAN] Postback updated: value=\(intValue), coarse=\(coarseStr ?? "nil"), lock=\(lock)")
134
+ resolve(nil)
135
+ }
164
136
  }
137
+ } else {
138
+ reject("UNAVAILABLE", "SKAdNetwork requires iOS 14.0+", nil)
165
139
  }
166
140
  }
167
141
 
@@ -0,0 +1,23 @@
1
+ // LayersSKANCompat.h
2
+ #import <Foundation/Foundation.h>
3
+
4
+ NS_ASSUME_NONNULL_BEGIN
5
+
6
+ @interface LayersSKANCompat : NSObject
7
+
8
+ // Update conversion/fine value using the best available SKAdNetwork API.
9
+ // Calls completion with an NSError when the underlying API reports one, or nil on success/fallback.
10
+ + (void)updateConversionValue:(NSInteger)value
11
+ completion:(void (^ _Nullable)(NSError * _Nullable error))completion;
12
+
13
+ // Update postback with fine/coarse/lock using the best available SKAdNetwork API.
14
+ // coarseString accepts @"low" | @"medium" | @"high" (case-insensitive) or nil.
15
+ + (void)updatePostbackConversionValue:(NSInteger)fineValue
16
+ coarseString:(NSString * _Nullable)coarseString
17
+ lockWindow:(BOOL)lockWindow
18
+ completion:(void (^ _Nullable)(NSError * _Nullable error))completion;
19
+
20
+ @end
21
+
22
+ NS_ASSUME_NONNULL_END
23
+
@@ -0,0 +1,118 @@
1
+ // LayersSKANCompat.m
2
+ #import "LayersSKANCompat.h"
3
+ #import <objc/message.h>
4
+ #include <dlfcn.h>
5
+
6
+ @implementation LayersSKANCompat
7
+
8
+ static NSString *_Nullable LayersGetNSStringConstant(const char *symbolName) {
9
+ if (symbolName == NULL) return nil;
10
+ void *addr = dlsym(RTLD_DEFAULT, symbolName);
11
+ if (!addr) {
12
+ // Try with leading underscore fallback
13
+ char underscored[256];
14
+ size_t n = strlen(symbolName);
15
+ if (n + 2 < sizeof(underscored)) {
16
+ underscored[0] = '_';
17
+ memcpy(&underscored[1], symbolName, n);
18
+ underscored[n + 1] = '\0';
19
+ addr = dlsym(RTLD_DEFAULT, underscored);
20
+ }
21
+ }
22
+ if (!addr) return nil;
23
+ // NSString * const symbol => dlsym returns address of the pointer variable
24
+ return *((NSString * const *)addr);
25
+ }
26
+
27
+ static NSString *_Nullable LayersCoarseConstantForString(NSString *_Nullable coarseString) {
28
+ if (coarseString == nil) return nil;
29
+ NSString *key = [[coarseString lowercaseString] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
30
+ const char *symbol = NULL;
31
+ if ([key isEqualToString:@"high"]) {
32
+ symbol = "SKAdNetworkCoarseConversionValueHigh";
33
+ } else if ([key isEqualToString:@"medium"]) {
34
+ symbol = "SKAdNetworkCoarseConversionValueMedium";
35
+ } else if ([key isEqualToString:@"low"]) {
36
+ symbol = "SKAdNetworkCoarseConversionValueLow";
37
+ }
38
+ if (symbol) {
39
+ NSString *constant = LayersGetNSStringConstant(symbol);
40
+ if (constant) return constant;
41
+ }
42
+ // Fallback: pass through the provided string (SK_TYPED_ENUM is NSString *)
43
+ return coarseString;
44
+ }
45
+
46
+ + (void)updateConversionValue:(NSInteger)value
47
+ completion:(void (^ _Nullable)(NSError * _Nullable error))completion {
48
+ Class cls = NSClassFromString(@"SKAdNetwork");
49
+ if (!cls) { if (completion) completion(nil); return; }
50
+
51
+ SEL selPostback15 = NSSelectorFromString(@"updatePostbackConversionValue:completionHandler:");
52
+ if ([cls respondsToSelector:selPostback15]) {
53
+ // void +[SKAdNetwork updatePostbackConversionValue:(NSInteger)cv completionHandler:(void (^)(NSError * error))completion]
54
+ void (*msgSend)(id, SEL, NSInteger, void(^)(NSError *)) = (void *)objc_msgSend;
55
+ msgSend(cls, selPostback15, value, ^(NSError *error){ if (completion) completion(error); });
56
+ return;
57
+ }
58
+
59
+ SEL selLegacy = NSSelectorFromString(@"updateConversionValue:");
60
+ if ([cls respondsToSelector:selLegacy]) {
61
+ void (*msgSendLegacy)(id, SEL, NSInteger) = (void *)objc_msgSend;
62
+ msgSendLegacy(cls, selLegacy, value);
63
+ if (completion) completion(nil);
64
+ return;
65
+ }
66
+
67
+ if (completion) completion(nil);
68
+ }
69
+
70
+ + (void)updatePostbackConversionValue:(NSInteger)fineValue
71
+ coarseString:(NSString * _Nullable)coarseString
72
+ lockWindow:(BOOL)lockWindow
73
+ completion:(void (^ _Nullable)(NSError * _Nullable error))completion {
74
+ Class cls = NSClassFromString(@"SKAdNetwork");
75
+ if (!cls) { if (completion) completion(nil); return; }
76
+
77
+ NSString *coarseArg = LayersCoarseConstantForString(coarseString);
78
+
79
+ if (coarseArg != nil) {
80
+ // iOS 16.1+ with lockWindow
81
+ SEL sel161Lock = NSSelectorFromString(@"updatePostbackConversionValue:coarseValue:lockWindow:completionHandler:");
82
+ if ([cls respondsToSelector:sel161Lock]) {
83
+ void (*msgSend)(id, SEL, NSInteger, NSString * _Nullable, BOOL, void(^)(NSError *)) = (void *)objc_msgSend;
84
+ msgSend(cls, sel161Lock, fineValue, coarseArg, lockWindow, ^(NSError *error){ if (completion) completion(error); });
85
+ return;
86
+ }
87
+
88
+ // iOS 16.1+ (fine + coarse)
89
+ SEL sel161 = NSSelectorFromString(@"updatePostbackConversionValue:coarseValue:completionHandler:");
90
+ if ([cls respondsToSelector:sel161]) {
91
+ void (*msgSend2)(id, SEL, NSInteger, NSString * _Nullable, void(^)(NSError *)) = (void *)objc_msgSend;
92
+ msgSend2(cls, sel161, fineValue, coarseArg, ^(NSError *error){ if (completion) completion(error); });
93
+ return;
94
+ }
95
+ // Fall through to fine-only if 16.1 coarse variants are unavailable
96
+ }
97
+
98
+ // iOS 15.4+ (fine only)
99
+ SEL sel154 = NSSelectorFromString(@"updatePostbackConversionValue:completionHandler:");
100
+ if ([cls respondsToSelector:sel154]) {
101
+ void (*msgSend3)(id, SEL, NSInteger, void(^)(NSError *)) = (void *)objc_msgSend;
102
+ msgSend3(cls, sel154, fineValue, ^(NSError *error){ if (completion) completion(error); });
103
+ return;
104
+ }
105
+
106
+ // Fallback to legacy (iOS 14+)
107
+ SEL selLegacy = NSSelectorFromString(@"updateConversionValue:");
108
+ if ([cls respondsToSelector:selLegacy]) {
109
+ void (*msgSendLegacy)(id, SEL, NSInteger) = (void *)objc_msgSend;
110
+ msgSendLegacy(cls, selLegacy, fineValue);
111
+ if (completion) completion(nil);
112
+ return;
113
+ }
114
+
115
+ if (completion) completion(nil);
116
+ }
117
+
118
+ @end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@layers/react-native",
3
- "version": "0.2.0-alpha.4",
3
+ "version": "0.2.0-alpha.6",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },