apache / cordova-ios

Apache Cordova iOS
https://cordova.apache.org/
Apache License 2.0
2.15k stars 986 forks source link

Any alternative to CDVCommandDelegateImpl which is removed from public classes? #1410

Closed anilgunnam closed 2 months ago

anilgunnam commented 2 months ago

We have upgraded from cordova-ios 6.3 to 7. After upgrade cordova iOS build is failing as one of our plugin uses CDVCommandDelegateImpl. Why this is removed from public classes? Is there alternative to the class CDVCommandDelegateImpl which we can use in our plugin?

dpogue commented 2 months ago

A CDVPlugin has a commandDelegate property that is a CDVCommandDelegate. CDVCommandDelegate is a protocol (interface) that is part of the public API.

CDVCommandDelegateImpl is the private implementation of that interface, and was never intended to be exposed as public API. In practice, the CDVPlugin commandDelegate is a CDVCommandDelegateImpl instance, but that is an implementation detail. Everything that a plugin should need to do with the command delegate is available on the CDVCommandDelegate protocol.

anilgunnam commented 1 month ago

In the plugin we use, Main plugin class which extends CDVPlugin has the below, it's using commandDelgate from CDVPlugin: __weak CDVCommandDelegateImpl* delegate = self.commandDelegate;

After this it calls other class in plugin by passing this commanddelegate as parameter. In other class header, import is defined in the as there are methods which has this CDVCommandDelegateImpl parameter:

import <Cordova/CDVCommandDelegateImpl.h>

If i try to use the CDVCommandDelegate interface instead of CDVCommandDelegateImpl in the method declaration, it says invalid type. Any idea on how to fix this?

dpogue commented 1 month ago

You'll need to change the other methods to take CDVCommandDelegate* instead of CDVCommandDelegateImpl*

anilgunnam commented 1 month ago

As, i mentioned earlier, already tried replacing CDVCommandDelegateImpl with CDVCommandDelegate in all header and implementation files like below:

import <Cordova/CDVCommandDelegate.h>

(void) startLogin: (CDVCommandDelegate*) commandDelegate
withCallbackId: (NSString*) callbackId;

Now it is showing an error at startLogin saying : Expected a type for CDVCommandDelegate*

dpogue commented 1 month ago

Try id<CDVCommandDelegate> rather than CDVCommandDelegate* (since CDVCommandDelegate is a protocol not a class).

id<CDVCommandDelegate> means a pointer to a class instance that implements the CDVCommandDelegate protocol

anilgunnam commented 1 month ago

It's working now. Thank you very much..