Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Can't load a file from documents directory into the webview / '_file_' prefix causes SIGBART on iOS #133

Closed
JRR-OSU opened this issue Jul 28, 2018 · 12 comments

Comments

@JRR-OSU
Copy link

JRR-OSU commented Jul 28, 2018

I recently uncovered a treasure trove of bugs with this plugin after migrating to 2.0. Previously we were on 1.1.19 and had no issues loading a local audio file into a waveform on iOS. For my current project we need to update our plugin to > 2.0 to be able to interface with Ionic Pro, however this completely broke loading in local files into the waveform container on iOS.

This is the line that does it: this.wavesurfer.load('_file_' + this.file.documentsDirectory.replace(/file:\/\//g, '')+ fileName);

Now previously, on 1.1.19, this line worked as, but this does not work on 2.0: this.wavesurfer.load(this.file.documentsDirectory.replace(/file:\/\//g, '')+ fileName;

I've tried using '_file_', "file://" and "cdvfile://". None work.

When trying with the '_file_' prefix, I get a SIGBART on iOS.

image

Bug 1: self.CDV_LOCAL_SERVER is getting set to nil somewhere
Bug 2: If I hard code the local server path, I get a SIGBART deep inside the engine code. Can post more on that later.

Is there something I'm missing here? I get that the webview now runs inside the local server with a different path, but how can i adjust my code to be able to load my waveform??

Help is needed urgently, thanks.

@scottmizo
Copy link

I'm running into the same issue with 2.0.1 when using Ionic.WebView.convertFileSrc() to generate a URL from a file entry.

To my novice eyes, it appears the file handler is getting set prior to CDV_LOCAL_SERVER bing defined.

workaround - *serverUrl = @"http://localhost:8080"

@JRR-OSU
Copy link
Author

JRR-OSU commented Jul 29, 2018

This is the result I get when using the workaround...

screen shot 2018-07-29 at 3 19 27 pm

@matejkramny
Copy link
Contributor

@JRR-OSU that means the file is missing from the filesystem

@matejkramny
Copy link
Contributor

Sorry messed up the merge request. Present now on #135

@olivermuc
Copy link

I'm seeing the same issues with accessing local files since the upgrade.
In the previous 1x version, a mere "file://" (or not for iOS) would do the trick.

I simply updated to cordova-plugin-ionic-webview v2 and it broke local file access for Android:
I tried both hardcoding the server address and using
window.Ionic.WebView.convertFileSrc(filePath);
both produce the same result in fact, eg:
http://localhost:8080/_file_/data/user/0/com....some.app/files/assets/e6d1ac1d14b6f15f1124dab9e7488ff8"

I don't see any security/access related errors but also nothing shows, leaving images broken.

On iOS it is even worse, I too see the dreaded "signal SIGABRT" error which leads to crashing the app:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString replaceOccurrencesOfString:withString:options:range:]: nil argument'
*** First throw call stack:
(0x181afed8c 0x180cb85ec 0x181afec6c 0x181a0c1a8 0x18245fe58 0x100990c60 0x1009a3e34 0x10099d274 0x10099f8f4 0x1009a0ee0 0x1009a0738 0x10112919c 0x1011011dc 0x10110119c 0x101112a00 0x101112500 0x181723fac 0x181723b08)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

@matejkramny
Copy link
Contributor

@olivermuc try patching CDVWKWebViewEngine.m with my MR

@olivermuc
Copy link

Excellent @matejkramny - I sincerely hope we can get this fix in asap. Awesome catch!

@ghost
Copy link

ghost commented Jul 31, 2018

@matejkramny Your MR worked perfectly for me. Thanks

@JRR-OSU
Copy link
Author

JRR-OSU commented Jul 31, 2018

@matejkramny Thanks for posting a fix. I have no idea why the person that wrote this decided to put nil values everywhere with no nil checks. There are other issues with the range checks for and

barnslig pushed a commit to barnslig/cordova-plugin-ionic-webview that referenced this issue Aug 30, 2018
* fix nil reference to CDV_LOCAL_SERVER

fixes ionic-team#133

* remove empty spaces

* remove more empty spaces

* rename local basePath variable
@Mapiac
Copy link

Mapiac commented Mar 13, 2019

Wondering @matejkramny did you find a fix w Android? Or maybe @JRR-OSU or @olivermuc did you guys have Android issues?

@JRR-OSU
Copy link
Author

JRR-OSU commented Mar 14, 2019

@Mapiac I didn't have issues on Android simply because I went with Crosswalk to avoid issues like this. Also I think Android avoided these issues altogether in the way that it handles the HTTP server. Previously the Ionic team used essentially a webserver plugin written by someone else on iOS that clearly didn't handle things like range requests properly. I think in the latest iterations they got rid of it. I needed to support devices back to iOS 9, so I just ended up fixing bugs myself. Was tedious as hell. Once I was able to get Crosswalk to build on Android, I've since had zero issues.

Edit: Looks like they fixed Android in commit 6f18248.

@intermedia54
Copy link

Hello
i must add this [self updateBindPath];
but my original code into CDVWKWebViewEngine.m is self.basePath = wwwPath;
Same problem for the others modifications
Any idea ?
Best regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants