apache / cordova-plugin-file-transfer

Apache Cordova File Transfer Plugin
https://cordova.apache.org/
Apache License 2.0
595 stars 888 forks source link

No known instance method for selector 'userAgent' in CDVFileTransfer.m #258

Closed alssl-ross closed 3 years ago

alssl-ross commented 4 years ago

Bug Report

Problem

When building using cordova-ios v6.0.0 an error is thrown saying:

"No known instance method for selector 'userAgent' in CDVFileTransfer.m"

What is expected to happen?

iOS build and run without error.

What does actually happen?

Error occurs as above

Information

The error occurs on line 107 of CDVFileTransfer.m":

NSString* userAgent = [self.commandDelegate userAgent];

Command or Code

Create a Cordova v9 project using cordova-ios 6.0.0 platform and version 1.7.1 of cordova-plugin-file-transfer run: cordova build ios

Environment, Platform, Device

Build error occurs using Cordova v9. cordova-ios 6.0.0 cordova-file-transfer-plugin v1.7.1

Checklist

kokitang commented 4 years ago

+1

jansc commented 4 years ago

+1

fabmesto commented 4 years ago

Same error with: cordova-ios: 6.0.0 cordova-plugin-file-transfer : 1.7.1

jansc commented 4 years ago

By removing lines 107-110 from CDVFileTransfer.m I was able to compile:

    NSString* userAgent = [self.commandDelegate userAgent];
    if (userAgent) {
        [req setValue:userAgent forHTTPHeaderField:@"User-Agent"];
    }
kolbasa commented 4 years ago

Thank you very much, I'll try that. You can no longer publish an app with cordova-ios v5.1.1. ~This issue should be a top priority.~ I have only just read that the plugin is deprecated :D.

fabmesto commented 4 years ago

is there any alternative to this plugin?

kolbasa commented 4 years ago

https://cordova.apache.org/blog/2017/10/18/from-filetransfer-to-xhr2.html

alssl-ross commented 4 years ago

I did go through the process of moving from this plugin to XHR but found that it failed for downloads of large zip files, causing me to revert back to this plugin.

I can compile now thanks to @jansc's comment above. I'm wondering if there is any effect on functionality from removing the userAgent lines. I've not been able to test for myself as yet.

vtellez commented 4 years ago

Same error with: cordova-ios: 6.0.0 cordova-plugin-file-transfer : 1.7.1

I cant not compile with @jansc Solution because Ive got: Plugins/cordova-plugin-inappbrowser/CDVWKInAppBrowser.m:27:9: 'Cordova/CDVUserAgentUtil.h' file not found if I delete Lines 107-110

kolbasa commented 4 years ago

Same error with: cordova-ios: 6.0.0 cordova-plugin-file-transfer : 1.7.1

I cant not compile with @jansc Solution because Ive got: Plugins/cordova-plugin-inappbrowser/CDVWKInAppBrowser.m:27:9: 'Cordova/CDVUserAgentUtil.h' file not found if I delete Lines 107-110

That was fixed on the master branch of cordova-plugin-inappbrowser: https://github.com/apache/cordova-plugin-inappbrowser/pull/715

sohanpc commented 4 years ago

By removing lines 107-110 from CDVFileTransfer.m I was able to compile:

    NSString* userAgent = [self.commandDelegate userAgent];
    if (userAgent) {
        [req setValue:userAgent forHTTPHeaderField:@"User-Agent"];
    }

It's working for me. Thank you for saving my time

alssl-ross commented 4 years ago

Given the plugin is deprecated, is it worth creating a pull request? I'm not sure if anyone is able to merge the pull request if it was created.

I've forked this repository and made this change in if it's of use to anyone:

https://github.com/alssl-ross/cordova-plugin-file-transfer

MrJohn2014 commented 4 years ago

Same issue here. I just comment lane 107-110 and my project could build successfully.

hefler commented 4 years ago

Although @alssl-ross did a fork removing the lines, I thought about combining @kolbasa 's solution tip into an own fork so that checking still happening: https://github.com/zoopit/cordova-plugin-file-transfer

sc0ttdav3y commented 4 years ago

Please @alssl-ross create a PR, and hopefully someone with access can merge it in.

EinfachHans commented 3 years ago

I switched to use this Fork

Lyfei commented 3 years ago

By removing lines 107-110 from CDVFileTransfer.m I was able to compile:

    NSString* userAgent = [self.commandDelegate userAgent];
    if (userAgent) {
        [req setValue:userAgent forHTTPHeaderField:@"User-Agent"];
    }

After deleting, my network request will not succeed. It seems that userAgent is needed

timbru31 commented 3 years ago

I've created a thread on the dev mailing list to discuss the matter with this plugin. It would help us PMC members to understand the reasons why you rely on the plugin (too) and especially the reasons why you can't migrate to the proposed XHR/fetch alternative.

https://lists.apache.org/thread.html/r4f85264a457ca57301cea226310f920b7f08e5657924a89899ab2b58%40%3Cdev.cordova.apache.org%3E

HarelM commented 3 years ago

@timbru31 I have the same issue as @alssl-ross describes. I have a few lerge files that I need to download from my server and save to the file system - total size of the files is 500Mb. Each file is between 100Mb and 300Mb. I can't split those files into smaller files because they are sqlite database files and splitting them would be a headache. When I download them using angular/ionic http client the file is loaded into memory before I can store it in the file system using the file-plugin. In some cases, specifically on iOS, this causes a "white screen of death". Somewhat related to this issue (see my comment at the end) https://github.com/apache/cordova-plugin-file/issues/364 When all I want to do is download a file and store it somewhere in the application folders there's a problem in iOS and sometimes it fails when not using this plugin. I think the problem is related to how much memory is used by the webview, not sure though...

timbru31 commented 3 years ago

@HarelM could you please share this insight with the dev mailing list as requested? I'm pretty sure not all active PMC members and committers are watching this issue.

DominicGBauer commented 3 years ago

@timbru31 I can't seem to reply to the mailing list but looking at the solution proposed by cordova of using window.requestFileSystem doesn't seem to be a viable solution anymore.

Considering what MDN docs say about it https://developer.mozilla.org/en-US/docs/Web/API/Window/requestFileSystem.

"Even compared to the rest of the File and Directory Entries API, requestFileSystem() is especially non-standard; only Chrome implements it, and all other browser makers have decided that they will not implement it. It has even been removed from the proposed specification. Do not use this method!"

It also doesn't seem to be in TypeScript typings.

HarelM commented 3 years ago

I'm pretty sure I already added my comments to that thread, but I don't see it there for some reason. I sent another mail, I hope it will be added...

sandip7878 commented 3 years ago

By removing lines 107-110 from CDVFileTransfer.m I was able to compile:

    NSString* userAgent = [self.commandDelegate userAgent];
    if (userAgent) {
        [req setValue:userAgent forHTTPHeaderField:@"User-Agent"];
    }

It's working for me. Thank you

imdox commented 3 years ago

By removing lines 107-110 from CDVFileTransfer.m I was able to compile:

    NSString* userAgent = [self.commandDelegate userAgent];
    if (userAgent) {
        [req setValue:userAgent forHTTPHeaderField:@"User-Agent"];
    }

It's working for me. Thank you for saving my time

its not working.... when i comment this lines, create following issue

Screenshot 2020-12-08 at 11 19 15 AM
imdox commented 3 years ago

Same error with: cordova-ios: 6.0.0 cordova-plugin-file-transfer : 1.7.1

I cant not compile with @jansc Solution because Ive got: Plugins/cordova-plugin-inappbrowser/CDVWKInAppBrowser.m:27:9: 'Cordova/CDVUserAgentUtil.h' file not found if I delete Lines 107-110

facing same issue.

XtreZz commented 3 years ago

will this be released soon ? i want to know if i should have another approach on this or wait for the release. Thanks

rolinger commented 3 years ago

@kolbasa

Thank you very much, I'll try that. You can no longer publish an app with cordova-ios v5.1.1. ~This issue should be a top priority.~ I have only just read that the plugin is deprecated :D.

This is not true. I am using Xcode 12, and my Ionic v1 app is using cordova-ios @5.1.1, everything compiles just fine and is accepted by Apple. What Apple will no longer accept are apps still using UIWebView - everyone must convert to WKWebView

timbru31 commented 3 years ago

Please note, that the deadline for updating UIWebView based apps has been extended by an unknown time: https://developer.apple.com/news/?id=edwud51q

rolinger commented 3 years ago

@timbru31 - technically true, but for apps that are already on the store front. New apps are required to use WKWebView. I have two apps, one still on UIWebView that is currently being accepted, and a new app (that is a splintered service from the first app) that had to be submitted with WKWebView. Any chance you could take a look at the bug I submitted last night, related to result.lengthComputable in success callback?

serverbroad commented 3 years ago

By removing lines 107-110 from CDVFileTransfer.m I was able to compile:

    NSString* userAgent = [self.commandDelegate userAgent];
    if (userAgent) {
        [req setValue:userAgent forHTTPHeaderField:@"User-Agent"];
    }

work for me

trackmyapp commented 3 years ago

@vtellez and @imdox Did you find any alternative solution or workaround to compile the code? Or is the transition off of this plugin to https://cordova.apache.org/blog/2017/10/18/from-filetransfer-to-xhr2.html the only solution?

trackmyapp commented 3 years ago

By removing lines 107-110 from CDVFileTransfer.m I was able to compile:

    NSString* userAgent = [self.commandDelegate userAgent];
    if (userAgent) {
        [req setValue:userAgent forHTTPHeaderField:@"User-Agent"];
    }

work for me

worked for me too but had to update the plugin "cordova-plugin-ionic-webview". So don't forget to update your other plugins.

markdegrootnl commented 3 years ago

Can this fix be released please?

regnete commented 3 years ago

Downloading many or large files via XHR is very slow in cordova even if we use chunked downloads (Range-Header). Looks like passing the byte array from javascript to the native backend is the bottleneck. The app hangs while transfering the chunks to the native. So using XHR is not an option for us na d we switched back to this plugin. see https://github.com/apache/cordova-plugin-file/issues/364 When will this fix be released?

msudol commented 3 years ago

too bad someone can't just develop a plugin that lets us use the same methods as cordova-file-transfer, with the XHR method, I believe that would be called a shim, or wrapper plugin, or post a more idiot dev friendly transition article.. my code base relies heavily on something that looks like this:

var ft = new FileTransfer();
ft.upload(imageURI, app.image_upload, win, fail, options);

If I could just load something using the XHR method that would let me create a filetransfer call that would be spectacular

rolinger commented 3 years ago

@msudol - why don't you contribute to the project versus criticizing it. I am certain everyone would appreciate the effort.

msudol commented 3 years ago

@msudol - why don't you contribute to the project versus criticizing it. I am certain everyone would appreciate the effort.

I made no criticism, only a request. Your comment is cringy, unwarranted, and provides even less contribution than mine. Where is your PR speaking of contributing.

rolinger commented 3 years ago

@msudol - too bad someone can't just develop a plugin that lets us use the same methods as cordova-file-transfer

Doesn't sound like a request....reads like a whiny complaint. Just sayin'. Moving along now...

timbru31 commented 3 years ago

Please be civil :)

I'll remove any other off-topic comments after this one without a warning. Thanks!

mirko77 commented 3 years ago

Quick question, on cordova-ios 6.2.0 which by default uses WKWebView, is it only a matter of commenting out those 4 lines of code? Our app uploads video files around 200/300 MB, we are refactoring to WKWebView as per Apple requirements.

NSString* userAgent = [self.commandDelegate userAgent];
    if (userAgent) {
        [req setValue:userAgent forHTTPHeaderField:@"User-Agent"];
    }
regnete commented 3 years ago

@mirko77 I'm using this fork. Works for me. https://github.com/sitewaerts/cordova-plugin-file-transfer. Diff: https://github.com/apache/cordova-plugin-file-transfer/compare/master...sitewaerts:master

I created that fork to merge the fixes from https://github.com/zoopit/cordova-plugin-file-transfer plus the current commits of https://github.com/apache/cordova-plugin-file-transfer

mirko77 commented 3 years ago

@mirko77 I'm using this fork. Works for me. https://github.com/sitewaerts/cordova-plugin-file-transfer. Diff: master...sitewaerts:master

I created that fork to merge the fixes from https://github.com/zoopit/cordova-plugin-file-transfer plus the current commits of https://github.com/apache/cordova-plugin-file-transfer

Thanks, very useful, I will give it a try

markdegrootnl commented 3 years ago

I'm using https://github.com/dpa99c/cordova-plugin-file-transfer for now

regnete commented 3 years ago

I'm using https://github.com/dpa99c/cordova-plugin-file-transfer for now

But thats 12 commits behind apache:master.

Noext commented 3 years ago

still not working on cordova 10

mirko77 commented 3 years ago

@Noext I do not think this repository ever will, try the linked forks

aacassandra commented 3 years ago

hub.com/dpa99c/cordova-plugin-file-transfer

thankyou, its works with capacitor 3 and last ionic/vue 2021

FranGhe commented 3 years ago

Just a question (I have loose some comments) but these plugins https://github.com/dpa99c/cordova-plugin-file-transfer https://github.com/sitewaerts/cordova-plugin-file-transfer work for cordova 10?

Excuse my ignorance, but if they work... why to install them the command is always the same? cordova plugin add cordova-plugin-file-transfer

I have to do something else?

sanderschnydrig commented 2 years ago

To anyone facing this issue this is the only one that worked for me:

(add this to dependencies)

"cordova-plugin-file-transfer": "https://github.com/dpa99c/cordova-plugin-file-transfer/tarball/446b175154491f67bc04a657041a26bc5db92b30",
regnete commented 2 years ago

Excuse my ignorance, but if they work... why to install them the command is always the same? cordova plugin add cordova-plugin-file-transfer

I have to do something else?

cordova plugin add https://github.com/sitewaerts/cordova-plugin-file-transfer