Add Callback Stuff
This commit is contained in:
parent
8259cc3dca
commit
0ef2c018fe
Binary file not shown.
@ -9,6 +9,11 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#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 showAlert(const char *title, const char *message, bool showCancel);
|
||||||
|
|
||||||
void showKeyboardAlert(const char *title, const char *message, const char *placeholder);
|
void showKeyboardAlert(const char *title, const char *message, const char *placeholder);
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
typedef void (^SwiftCallback)(NSString *result);
|
||||||
|
|
||||||
static char *keyboardInput = NULL;
|
static char *keyboardInput = NULL;
|
||||||
|
|
||||||
@ -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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user