@virex-tech/paywallo-sdk 2.5.0 → 2.5.2
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 +23 -2
- package/android/src/main/AndroidManifest.xml +8 -0
- package/android/src/main/java/com/paywallo/sdk/PaywalloStoreKitModule.kt +14 -2
- package/dist/index.d.mts +40 -29
- package/dist/index.d.ts +40 -29
- package/dist/index.js +457 -304
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +444 -291
- package/dist/index.mjs.map +1 -1
- package/ios/PaywalloAPNSProxy.m +138 -0
- package/package.json +1 -1
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
#import <UIKit/UIKit.h>
|
|
3
|
+
#import <objc/runtime.h>
|
|
4
|
+
|
|
5
|
+
//
|
|
6
|
+
// PaywalloAPNSProxy — captura automática do token APNs via swizzling do AppDelegate.
|
|
7
|
+
//
|
|
8
|
+
// OPT-IN, DESLIGADO POR PADRÃO. Integrações existentes NÃO são afetadas: nada é
|
|
9
|
+
// swizzlado a menos que o app declare, no Info.plist:
|
|
10
|
+
//
|
|
11
|
+
// <key>PaywalloEnableAPNSSwizzling</key>
|
|
12
|
+
// <true/>
|
|
13
|
+
//
|
|
14
|
+
// Quando ligado, este proxy intercepta os callbacks de push do AppDelegate do app
|
|
15
|
+
// e posta as mesmas NSNotification que PaywalloNotifications.swift já observa
|
|
16
|
+
// (PaywalloAPNSTokenReceived / PaywalloRemoteNotificationReceived), dispensando
|
|
17
|
+
// qualquer código manual no AppDelegate. A implementação original do host (se
|
|
18
|
+
// existir) é sempre chamada em seguida — o proxy nunca a substitui.
|
|
19
|
+
//
|
|
20
|
+
// ⚠️ Este arquivo faz method swizzling em Objective-C runtime (padrão Firebase/
|
|
21
|
+
// OneSignal). DEVE ser compilado e testado em dispositivo físico antes de
|
|
22
|
+
// publicar. Por isso é opt-in: o caminho padrão e garantido continua sendo a
|
|
23
|
+
// fiação manual do AppDelegate documentada em docs/push-setup.md.
|
|
24
|
+
//
|
|
25
|
+
|
|
26
|
+
static NSString *const kPaywalloEnableFlag = @"PaywalloEnableAPNSSwizzling";
|
|
27
|
+
static NSString *const kPaywalloTokenNotification = @"PaywalloAPNSTokenReceived";
|
|
28
|
+
static NSString *const kPaywalloRecvNotification = @"PaywalloRemoteNotificationReceived";
|
|
29
|
+
|
|
30
|
+
// IMPs originais do host, chamadas após postarmos a notificação.
|
|
31
|
+
static IMP gOriginalDidRegister = NULL;
|
|
32
|
+
static IMP gOriginalDidReceive = NULL;
|
|
33
|
+
|
|
34
|
+
static BOOL PaywalloSwizzlingEnabled(void) {
|
|
35
|
+
id flag = [[NSBundle mainBundle] objectForInfoDictionaryKey:kPaywalloEnableFlag];
|
|
36
|
+
return [flag isKindOfClass:[NSNumber class]] && [flag boolValue];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static NSString *PaywalloHexFromToken(NSData *deviceToken) {
|
|
40
|
+
if (deviceToken.length == 0) { return @""; }
|
|
41
|
+
const unsigned char *bytes = (const unsigned char *)deviceToken.bytes;
|
|
42
|
+
NSMutableString *hex = [NSMutableString stringWithCapacity:deviceToken.length * 2];
|
|
43
|
+
for (NSUInteger i = 0; i < deviceToken.length; i++) {
|
|
44
|
+
[hex appendFormat:@"%02x", bytes[i]];
|
|
45
|
+
}
|
|
46
|
+
return hex;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// --- IMPs do proxy --------------------------------------------------------
|
|
50
|
+
|
|
51
|
+
static void Paywallo_didRegister(id self, SEL _cmd, UIApplication *app, NSData *deviceToken) {
|
|
52
|
+
NSString *token = PaywalloHexFromToken(deviceToken);
|
|
53
|
+
[[NSNotificationCenter defaultCenter] postNotificationName:kPaywalloTokenNotification
|
|
54
|
+
object:nil
|
|
55
|
+
userInfo:@{ @"token": token }];
|
|
56
|
+
if (gOriginalDidRegister) {
|
|
57
|
+
((void (*)(id, SEL, UIApplication *, NSData *))gOriginalDidRegister)(self, _cmd, app, deviceToken);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static void Paywallo_didReceive(id self, SEL _cmd, UIApplication *app,
|
|
62
|
+
NSDictionary *userInfo,
|
|
63
|
+
void (^completionHandler)(UIBackgroundFetchResult)) {
|
|
64
|
+
[[NSNotificationCenter defaultCenter] postNotificationName:kPaywalloRecvNotification
|
|
65
|
+
object:nil
|
|
66
|
+
userInfo:@{ @"payload": (userInfo ?: @{}) }];
|
|
67
|
+
if (gOriginalDidReceive) {
|
|
68
|
+
((void (*)(id, SEL, UIApplication *, NSDictionary *, void (^)(UIBackgroundFetchResult)))gOriginalDidReceive)
|
|
69
|
+
(self, _cmd, app, userInfo, completionHandler);
|
|
70
|
+
} else if (completionHandler) {
|
|
71
|
+
completionHandler(UIBackgroundFetchResultNoData);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Instala newImp em cls para sel. Se cls já implementa sel, guarda a IMP original
|
|
76
|
+
// (para o proxy chamar em seguida) e a substitui; senão, adiciona o método.
|
|
77
|
+
static void PaywalloInstall(Class cls, SEL sel, IMP newImp, const char *types, IMP *storeOriginal) {
|
|
78
|
+
if (cls == Nil || sel == NULL) { return; }
|
|
79
|
+
if (class_addMethod(cls, sel, newImp, types)) {
|
|
80
|
+
// Host não implementava (nem por herança alcançável aqui): método adicionado.
|
|
81
|
+
*storeOriginal = NULL;
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
// Host já implementa: guarda original e troca a implementação.
|
|
85
|
+
Method existing = class_getInstanceMethod(cls, sel);
|
|
86
|
+
*storeOriginal = method_getImplementation(existing);
|
|
87
|
+
method_setImplementation(existing, newImp);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
static void PaywalloInstallProxyOnDelegate(id<UIApplicationDelegate> delegate) {
|
|
91
|
+
if (delegate == nil) { return; }
|
|
92
|
+
static dispatch_once_t onceToken;
|
|
93
|
+
dispatch_once(&onceToken, ^{
|
|
94
|
+
Class cls = [delegate class];
|
|
95
|
+
PaywalloInstall(cls,
|
|
96
|
+
@selector(application:didRegisterForRemoteNotificationsWithDeviceToken:),
|
|
97
|
+
(IMP)Paywallo_didRegister, "v@:@@", &gOriginalDidRegister);
|
|
98
|
+
PaywalloInstall(cls,
|
|
99
|
+
@selector(application:didReceiveRemoteNotification:fetchCompletionHandler:),
|
|
100
|
+
(IMP)Paywallo_didReceive, "v@:@@@?", &gOriginalDidReceive);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// --- Swizzle de setDelegate: para descobrir a classe do AppDelegate -------
|
|
105
|
+
|
|
106
|
+
static IMP gOriginalSetDelegate = NULL;
|
|
107
|
+
|
|
108
|
+
static void Paywallo_setDelegate(id self, SEL _cmd, id<UIApplicationDelegate> delegate) {
|
|
109
|
+
PaywalloInstallProxyOnDelegate(delegate);
|
|
110
|
+
if (gOriginalSetDelegate) {
|
|
111
|
+
((void (*)(id, SEL, id))gOriginalSetDelegate)(self, _cmd, delegate);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
@interface PaywalloAPNSProxy : NSObject
|
|
116
|
+
@end
|
|
117
|
+
|
|
118
|
+
@implementation PaywalloAPNSProxy
|
|
119
|
+
|
|
120
|
+
+ (void)load {
|
|
121
|
+
if (!PaywalloSwizzlingEnabled()) { return; }
|
|
122
|
+
|
|
123
|
+
// O delegate pode já estar setado quando este +load roda; cobrir ambos os casos:
|
|
124
|
+
// 1) Swizzlar setDelegate: para pegar atribuições futuras.
|
|
125
|
+
// 2) Se já existe um delegate, instalar imediatamente.
|
|
126
|
+
Method setDelegate = class_getInstanceMethod([UIApplication class], @selector(setDelegate:));
|
|
127
|
+
if (setDelegate) {
|
|
128
|
+
gOriginalSetDelegate = method_getImplementation(setDelegate);
|
|
129
|
+
method_setImplementation(setDelegate, (IMP)Paywallo_setDelegate);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
133
|
+
id<UIApplicationDelegate> existing = [UIApplication sharedApplication].delegate;
|
|
134
|
+
if (existing) { PaywalloInstallProxyOnDelegate(existing); }
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
@end
|
package/package.json
CHANGED