diff --git a/ios/Capacitor/Capacitor/CAPBridgeProtocol.swift b/ios/Capacitor/Capacitor/CAPBridgeProtocol.swift index 4afa4eb6f..579d9dcdc 100644 --- a/ios/Capacitor/Capacitor/CAPBridgeProtocol.swift +++ b/ios/Capacitor/Capacitor/CAPBridgeProtocol.swift @@ -38,13 +38,20 @@ import WebKit @available(*, deprecated, message: "Moved - equivalent is found on config.localURL") func getLocalUrl() -> String + @available(*, deprecated, renamed: "savedCall(withID:)") + func getSavedCall(_ callbackId: String) -> CAPPluginCall? + + @available(*, deprecated, renamed: "releaseCall(withID:)") + func releaseCall(callbackId: String) + // MARK: - Plugin Access func plugin(withName: String) -> CAPPlugin? // MARK: - Call Management - func getSavedCall(_ callbackId: String) -> CAPPluginCall? + func saveCall(_ call: CAPPluginCall) + func savedCall(withID: String) -> CAPPluginCall? func releaseCall(_ call: CAPPluginCall) - func releaseCall(callbackId: String) + func releaseCall(withID: String) // MARK: - JavaScript Handling // `js` is a short name but needs to be preserved for backwards compatibility. diff --git a/ios/Capacitor/Capacitor/CAPPlugin.m b/ios/Capacitor/Capacitor/CAPPlugin.m index 30aa3b8a4..63634d982 100644 --- a/ios/Capacitor/Capacitor/CAPPlugin.m +++ b/ios/Capacitor/Capacitor/CAPPlugin.m @@ -111,16 +111,16 @@ - (void)notifyListeners:(NSString *)eventName data:(NSDictionary - (void)addListener:(CAPPluginCall *)call { NSString *eventName = [call.options objectForKey:@"eventName"]; - [call setIsSaved:TRUE]; + [call setKeepAlive:TRUE]; [self addEventListener:eventName listener:call]; } - (void)removeListener:(CAPPluginCall *)call { NSString *eventName = [call.options objectForKey:@"eventName"]; NSString *callbackId = [call.options objectForKey:@"callbackId"]; - CAPPluginCall *storedCall = [self.bridge getSavedCall:callbackId]; + CAPPluginCall *storedCall = [self.bridge savedCallWithID:callbackId]; [self removeEventListener:eventName listener:storedCall]; - [self.bridge releaseCallWithCallbackId:callbackId]; + [self.bridge releaseCallWithID:callbackId]; } - (void)removeAllListeners:(CAPPluginCall *)call { diff --git a/ios/Capacitor/Capacitor/CAPPluginCall.h b/ios/Capacitor/Capacitor/CAPPluginCall.h index ce05fd319..46b3e67bc 100644 --- a/ios/Capacitor/Capacitor/CAPPluginCall.h +++ b/ios/Capacitor/Capacitor/CAPPluginCall.h @@ -9,7 +9,8 @@ typedef void(^CAPPluginCallErrorHandler)(CAPPluginCallError *error); @interface CAPPluginCall : NSObject -@property (nonatomic, assign) BOOL isSaved; +@property (nonatomic, assign) BOOL isSaved DEPRECATED_MSG_ATTRIBUTE("Use 'keepAlive' instead."); +@property (nonatomic, assign) BOOL keepAlive; @property (nonatomic, strong) NSString *callbackId; @property (nonatomic, strong) NSDictionary *options; @property (nonatomic, copy) CAPPluginCallSuccessHandler successHandler; @@ -17,5 +18,5 @@ typedef void(^CAPPluginCallErrorHandler)(CAPPluginCallError *error); - (instancetype)initWithCallbackId:(NSString *)callbackId options:(NSDictionary *)options success:(CAPPluginCallSuccessHandler)success error:(CAPPluginCallErrorHandler)error; -- (void)save; +- (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 85a203973..543b11ce2 100644 --- a/ios/Capacitor/Capacitor/CAPPluginCall.m +++ b/ios/Capacitor/Capacitor/CAPPluginCall.m @@ -11,8 +11,16 @@ - (instancetype)initWithCallbackId:(NSString *)callbackId options:(NSDictionary return self; } +- (BOOL)isSaved { + return self.keepAlive; +} + +- (void)setIsSaved:(BOOL)saved { + self.keepAlive = saved; +} + - (void)save { - self.isSaved = true; + self.keepAlive = true; } @end diff --git a/ios/Capacitor/Capacitor/CapacitorBridge.swift b/ios/Capacitor/Capacitor/CapacitorBridge.swift index 94d499ebc..edc20340e 100644 --- a/ios/Capacitor/Capacitor/CapacitorBridge.swift +++ b/ios/Capacitor/Capacitor/CapacitorBridge.swift @@ -303,10 +303,6 @@ internal class CapacitorBridge: NSObject, CAPBridgeProtocol { return plugin } - func savePluginCall(_ call: CAPPluginCall) { - storedCalls[call.callbackId] = call - } - // MARK: - CAPBridgeProtocol: Plugin Access @objc public func plugin(withName: String) -> CAPPlugin? { @@ -315,18 +311,34 @@ internal class CapacitorBridge: NSObject, CAPBridgeProtocol { // MARK: - CAPBridgeProtocol: Call Management - @objc public func getSavedCall(_ callbackId: String) -> CAPPluginCall? { - return storedCalls[callbackId] + @objc public func saveCall(_ call: CAPPluginCall) { + storedCalls[call.callbackId] = call + } + + @objc public func savedCall(withID: String) -> CAPPluginCall? { + return storedCalls[withID] } @objc public func releaseCall(_ call: CAPPluginCall) { - storedCalls.removeValue(forKey: call.callbackId) + releaseCall(withID: call.callbackId) + } + + @objc public func releaseCall(withID: String) { + storedCalls.removeValue(forKey: withID) + } + + // MARK: - Deprecated Versions + + @objc public func getSavedCall(_ callbackId: String) -> CAPPluginCall? { + return savedCall(withID: callbackId) } @objc public func releaseCall(callbackId: String) { - storedCalls.removeValue(forKey: callbackId) + releaseCall(withID: callbackId) } + // MARK: - Internal + func getDispatchQueue() -> DispatchQueue { return self.dispatchQueue } @@ -406,9 +418,9 @@ internal class CapacitorBridge: NSObject, CAPBridgeProtocol { formattingDatesAsStrings: plugin.shouldStringifyDatesInCalls) ?? [:], success: {(result: CAPPluginCallResult?, pluginCall: CAPPluginCall?) -> Void in if let result = result { - self?.toJs(result: JSResult(call: call, callResult: result), save: pluginCall?.isSaved ?? false) + self?.toJs(result: JSResult(call: call, callResult: result), save: pluginCall?.keepAlive ?? false) } else { - self?.toJs(result: JSResult(call: call, result: .dictionary([:])), save: pluginCall?.isSaved ?? false) + self?.toJs(result: JSResult(call: call, result: .dictionary([:])), save: pluginCall?.keepAlive ?? false) } }, error: {(error: CAPPluginCallError?) -> Void in if let error = error { @@ -424,8 +436,10 @@ internal class CapacitorBridge: NSObject, CAPBridgeProtocol { if let pluginCall = pluginCall { plugin.perform(selector, with: pluginCall) - if pluginCall.isSaved { - self?.savePluginCall(pluginCall) + if pluginCall.keepAlive { + self?.saveCall(pluginCall) + } else { + self?.releaseCall(pluginCall) } }