fix(ios): cast to CDVFile when getting the plugin by getCommandInstance (#385)

- `CDVCommandDelegate getCommandInstance` returns a `CDVPlugin` which does not know about the selectors of an inherited class like `CDVFile`. If not casted, XCode will throw an error like `error: no visible @interface for 'CDVPlugin' declares the selector 'filesystemForURL:'`.
This commit is contained in:
Manuel Beck
2026-01-19 23:13:59 +01:00
committed by GitHub
parent 41b060565b
commit 7b869a2276

View File

@@ -289,7 +289,7 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
delegate.source = source; delegate.source = source;
delegate.target = server; delegate.target = server;
delegate.trustAllHosts = trustAllHosts; delegate.trustAllHosts = trustAllHosts;
delegate.filePlugin = [self.commandDelegate getCommandInstance:@"File"]; delegate.filePlugin = (CDVFile *)[self.commandDelegate getCommandInstance:@"File"];
delegate.chunkedMode = chunkedMode; delegate.chunkedMode = chunkedMode;
return delegate; return delegate;
@@ -328,7 +328,8 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
if (sourceURL) { if (sourceURL) {
// Try to get a CDVFileSystem which will handle this file. // Try to get a CDVFileSystem which will handle this file.
// This requires talking to the current CDVFile plugin. // This requires talking to the current CDVFile plugin.
fs = [[self.commandDelegate getCommandInstance:@"File"] filesystemForURL:sourceURL]; CDVFile *filePlugin = (CDVFile *)[self.commandDelegate getCommandInstance:@"File"];
fs = [filePlugin filesystemForURL:sourceURL];
} }
if (fs) { if (fs) {
__weak CDVFileTransfer* weakSelf = self; __weak CDVFileTransfer* weakSelf = self;
@@ -430,7 +431,8 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
* Check here to see if it looks like the user passed in a raw filesystem path. (Perhaps they had the path saved, and were previously using it with the old version of File). If so, normalize it by removing empty path segments, and check with File to see if any of the installed filesystems will handle it. If so, then we will end up with a filesystem url to use for the remainder of this operation. * Check here to see if it looks like the user passed in a raw filesystem path. (Perhaps they had the path saved, and were previously using it with the old version of File). If so, normalize it by removing empty path segments, and check with File to see if any of the installed filesystems will handle it. If so, then we will end up with a filesystem url to use for the remainder of this operation.
*/ */
target = [target stringByReplacingOccurrencesOfString:@"//" withString:@"/"]; target = [target stringByReplacingOccurrencesOfString:@"//" withString:@"/"];
targetURL = [[self.commandDelegate getCommandInstance:@"File"] fileSystemURLforLocalPath:target].url; CDVFile *filePlugin = (CDVFile *)[self.commandDelegate getCommandInstance:@"File"];
targetURL = [filePlugin fileSystemURLforLocalPath:target].url;
} else { } else {
targetURL = [NSURL URLWithString:target]; targetURL = [NSURL URLWithString:target];
@@ -476,7 +478,7 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
delegate.target = [targetURL absoluteString]; delegate.target = [targetURL absoluteString];
delegate.targetURL = targetURL; delegate.targetURL = targetURL;
delegate.trustAllHosts = trustAllHosts; delegate.trustAllHosts = trustAllHosts;
delegate.filePlugin = [self.commandDelegate getCommandInstance:@"File"]; delegate.filePlugin = (CDVFile *)[self.commandDelegate getCommandInstance:@"File"];
delegate.backgroundTaskID = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ delegate.backgroundTaskID = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
[delegate cancelTransfer:delegate.connection]; [delegate cancelTransfer:delegate.connection];
}]; }];