Add Callback Stuff
This commit is contained in:
parent
8259cc3dca
commit
0ef2c018fe
Binary file not shown.
@ -9,6 +9,11 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void (^SwiftCallback)(NSString *result);
|
||||
|
||||
void RegisterCallback(NSString *identifier, SwiftCallback callback);
|
||||
void TriggerCallback(const char *cIdentifier);
|
||||
|
||||
void showAlert(const char *title, const char *message, bool showCancel);
|
||||
|
||||
void showKeyboardAlert(const char *title, const char *message, const char *placeholder);
|
||||
|
@ -12,6 +12,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void (^SwiftCallback)(NSString *result);
|
||||
|
||||
static char *keyboardInput = NULL;
|
||||
|
||||
UIWindowScene *getMainDeviceWindowScene() {
|
||||
@ -157,6 +159,40 @@ void clearKeyboardInput() {
|
||||
}
|
||||
}
|
||||
|
||||
static NSMutableDictionary<NSString*, SwiftCallback> *callbackStore;
|
||||
|
||||
void RegisterCallback(NSString *identifier, SwiftCallback callback) {
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
callbackStore = [NSMutableDictionary new];
|
||||
});
|
||||
|
||||
if (identifier && callback) {
|
||||
@synchronized(callbackStore) {
|
||||
callbackStore[identifier] = [callback copy]; // copy blocks
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TriggerCallback(const char *cIdentifier) {
|
||||
if (!cIdentifier) return;
|
||||
|
||||
// Convert C string to NSString
|
||||
NSString *identifier = [NSString stringWithUTF8String:cIdentifier];
|
||||
if (!identifier) return;
|
||||
|
||||
SwiftCallback callback = nil;
|
||||
@synchronized(callbackStore) {
|
||||
callback = callbackStore[identifier];
|
||||
if (callback) {
|
||||
[callbackStore removeObjectForKey:identifier]; // optional: remove after call
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
callback(identifier);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user