From df109aa1cfa1ea824e22feecbd2b7183a57fc693 Mon Sep 17 00:00:00 2001 From: Robin Genz Date: Fri, 27 Sep 2024 19:34:47 +0200 Subject: [PATCH] feat(core): expose `methodName` via `CAPPluginCall` (#7641) --- ios/Capacitor/Capacitor/CAPPluginCall.h | 5 ++++- ios/Capacitor/Capacitor/CAPPluginCall.m | 12 +++++++++++- ios/Capacitor/Capacitor/CapacitorBridge.swift | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/ios/Capacitor/Capacitor/CAPPluginCall.h b/ios/Capacitor/Capacitor/CAPPluginCall.h index 46b3e67bc8..129dba7ff2 100644 --- a/ios/Capacitor/Capacitor/CAPPluginCall.h +++ b/ios/Capacitor/Capacitor/CAPPluginCall.h @@ -12,11 +12,14 @@ typedef void(^CAPPluginCallErrorHandler)(CAPPluginCallError *error); @property (nonatomic, assign) BOOL isSaved DEPRECATED_MSG_ATTRIBUTE("Use 'keepAlive' instead."); @property (nonatomic, assign) BOOL keepAlive; @property (nonatomic, strong) NSString *callbackId; +@property (nonatomic, strong) NSString *methodName; @property (nonatomic, strong) NSDictionary *options; @property (nonatomic, copy) CAPPluginCallSuccessHandler successHandler; @property (nonatomic, copy) CAPPluginCallErrorHandler errorHandler; -- (instancetype)initWithCallbackId:(NSString *)callbackId options:(NSDictionary *)options success:(CAPPluginCallSuccessHandler)success error:(CAPPluginCallErrorHandler)error; +- (instancetype)initWithCallbackId:(NSString *)callbackId options:(NSDictionary *)options success:(CAPPluginCallSuccessHandler)success error:(CAPPluginCallErrorHandler)error DEPRECATED_MSG_ATTRIBUTE("Specify the method name as well."); + +- (instancetype)initWithCallbackId:(NSString *)callbackId methodName:(NSString *)methodName options:(NSDictionary *)options success:(CAPPluginCallSuccessHandler)success error:(CAPPluginCallErrorHandler)error; - (void)save DEPRECATED_MSG_ATTRIBUTE("Use the 'keepAlive' property instead."); @end diff --git a/ios/Capacitor/Capacitor/CAPPluginCall.m b/ios/Capacitor/Capacitor/CAPPluginCall.m index 543b11ce28..fc99de3835 100644 --- a/ios/Capacitor/Capacitor/CAPPluginCall.m +++ b/ios/Capacitor/Capacitor/CAPPluginCall.m @@ -3,8 +3,18 @@ @implementation CAPPluginCall -- (instancetype)initWithCallbackId:(NSString *)callbackId options:(NSDictionary *)options success:(CAPPluginCallSuccessHandler) success error:(CAPPluginCallErrorHandler) error { +- (instancetype)initWithCallbackId:(NSString *)callbackId options:(NSDictionary *)options success:(CAPPluginCallSuccessHandler) success error:(CAPPluginCallErrorHandler) error __deprecated { self.callbackId = callbackId; + self.methodName = @""; + self.options = options; + self.successHandler = success; + self.errorHandler = error; + return self; +} + +- (instancetype)initWithCallbackId:(NSString *)callbackId methodName:(NSString *)methodName options:(NSDictionary *)options success:(CAPPluginCallSuccessHandler) success error:(CAPPluginCallErrorHandler) error { + self.callbackId = callbackId; + self.methodName = methodName; self.options = options; self.successHandler = success; self.errorHandler = error; diff --git a/ios/Capacitor/Capacitor/CapacitorBridge.swift b/ios/Capacitor/Capacitor/CapacitorBridge.swift index 0847577f8a..ae8064428a 100644 --- a/ios/Capacitor/Capacitor/CapacitorBridge.swift +++ b/ios/Capacitor/Capacitor/CapacitorBridge.swift @@ -489,7 +489,7 @@ open class CapacitorBridge: NSObject, CAPBridgeProtocol { dispatchQueue.async { [weak self] in // let startTime = CFAbsoluteTimeGetCurrent() - let pluginCall = CAPPluginCall(callbackId: call.callbackId, + let pluginCall = CAPPluginCall(callbackId: call.callbackId, methodName: call.method, options: JSTypes.coerceDictionaryToJSObject(call.options, formattingDatesAsStrings: plugin.shouldStringifyDatesInCalls) ?? [:], success: {(result: CAPPluginCallResult?, pluginCall: CAPPluginCall?) in