native script: WebView Interface plugin unable to find local resource - webview

I am using webViewInterface plugin in nativescript 8 with webpack v5 I am trying to launch local downloaded file ex. video, audio, HTML files
I am able to download those files but while running that file with the help of webview I am getting
file not found
chromium: [INFO:CONSOLE(1)] "Uncaught TypeError: Cannot read property '_onNativeEvent' of undefined", source: chrome-error://chromewebdata/
In NativeScript, by default, the tilde (~) marks the app root folder (note the App and not the Project!). So if my file is located in <project-name>/app/index.html then I need to set a path like this ~/index.html.
this was working fine with natviescript v6 but after upgrading to nativescript v8 it broke.
can anyone please help???

The app folder is read-only on iOS (at least, on real devices, not necessarily on emulators). You'll need to download the files to either the temp or documents folder and then access from there.
As a reference, see my own struggle with this issue.

OK i have what seems to be the same issue. In my case when i migrated from nativescript 7 to 8 the webpack.config.ts was cleaned up.
In there was something useful that copied all my webview files.
I added some code to my webpack.config.js and now it seems to work
"src" is the folder containing my webview folder.
const webpack = require("#nativescript/webpack");
module.exports = (env) => {
webpack.init(env);
webpack.Utils.addCopyRule({
from: 'webviews/**',
context : 'src'
})
return webpack.resolveConfig();
};
The doc I used.
NS 8 : https://docs.nativescript.org/webpack.html#adding-a-copy-rule
Previous plugin used : https://webpack.js.org/plugins/copy-webpack-plugin/

Related

Flutter open local asset (PDF) in native application

I am trying to bundle my app with a PDF, and let the user open it in the native viewer.
I have tried:
Copying the data for the PDF to the "Temporary Directory" or the "Document Directory" (from path_provider) and opening from there
To open I am using 'url_launcher' to open the file. I have tried using both file://... urls and just passing the local path ie /.../ etc
The files definitely exist, it seems to be a permissions issue that the files in both locations, in both platforms, are in the app's sandbox.
The file definitely exists, and I can open PDFs from web URLs.
is this something flutter can do?
Update 12/8/19
I just got pinged by SO that this question has had a bunch of views and no good answers. For this project I ultimately tried Cordova, Flutter, React Native and eventually gave up and created two native apps to do what I needed to do. They worked OK but the client wanted to make a bunch of UX changes.
So in the end I wrapped the code from the native side of things into a flutter plugin and then did the UX in flutter. Thats the backstory, here is the technical specs of what I hacked together:
For iOS there was an example of using their PDF kit in iOS 11 from github, I did some work there and there was a bunch of manually created features in the repo, so I attached the PDFs I wanted to that project, and wrote a script to present them, then used the flutter bridge to launch.
For Android it was much the same - I copied the files from the app bundle (not flutter assets) to a temp directory and then created a share link and launched the pdf using the native system viewer.
All in all it was a massive stuff around, no fault of Flutter's though, like I said, I used a bunch of multi platform frameworks and none of them would accomplish the job in a satisfactory way. Im sure a better dev could come up with a workable solution though.
Edit: It has been mentioned to use a combination of url_launcher and open_file. They work great for external files but do not work for bundled assets.
I'm not quite sure if this is still a problem for you. But as I wanted to know the same thing, I tried to figure it out. Here is my result, but I have to mention, that I stored my file in the download folder:
install url_launcher and simple_permissions
add the following lines to your AndroidManifest.xml and the corresponding iOS equivalent:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Code for creating pdf:
SimplePermissions.requestPermission(Permission.WriteExternalStorage);
String dir = (await getExternalStorageDirectory()).path + "/download";
String filename = "$dir/" + title;
File f = new File(filename);
f.writeAsBytesSync(data);
Code for opening the file
var url = 'file://' + f.path;
if (await canLaunch(url)) {
await launch(url, forceSafariVC: false, forceWebView: false);
} else {
throw 'Could not launch $url';
}

How do I open a file from disk, in a Flutter app?

In a Flutter app I have a dart file located at FlutterTest\sandbox\lib\my_widget\my_widget.dart.
And I have an image located at FlutterTest\sandbox\lib\my_widget\imgs\myImage.png.
From my_widget.dart how can I point a file to this image, something along the lines of new File("???\my_widget\myImage.png")?
Just to clarify, in Java I could do something like MyClass.class.getResource("myImage.png").toString().
By the way if I print(Directory.current.path) it gives me simply /. And if I try to list the contents of this directory it tells me: "Directory listing failed, path = '/' (OS Error: Permission denied, errno = 13)". So I don't actually know where the current directory is.
You can directly access the file system but due to differences in android and iOS you'll probably end up using the path provider plugin. Also, see this flutter cookbook as they call it.
But if all you're trying to do is access a file from your build, you'll want to define it as an asset in your pubspec, and then access it using Flutter's AssetBundle (or Image.asset) rather than directly using File or Image.file. See the flutter documentation on assets.

libGDX FileHandle file not found on ios

I have bin folder in my android assets folder in which I store json file for my default values for my game.
I read this file using
FileHandle gameDataFile = Gdx.files.local("assets/bin/levels_data");
and this work perfect on android phones. Today I try to export my game for ios and I get this error:
File not found: assets/bin/levels_data (Local)
I tried to remove assets from path but I get same error again (File not found: bin/levels_data (Local))
Can some one tell me how to solve this, how to read from iso, file that is located in assets folder?
I want to mentioned that asset loader loads all other filed(images, textures, sounds...) that are located in assets folder on ios . Problem is when I try to read file with Gdx.files.local but only on ios device ( simulator for now)
Thanks
To access internal package files (like assets on Android), you have to use internal (not local) file handle. Try this:
FileHandle gameDataFile = Gdx.files.internal("bin/levels_data");

How to deploy arbitrary resources for React Native with CodePush

I'm using CodePush to deploy the js bundle and a couple of resources to my react-native iOS app. Instead of using the react-native bundler to collect all the static images from my project I have a build step that just copies a folder called "static" into release/assets. But beside the "static" folder I als have other folders in release/assets that contain images and videos wich are use dynamically in the app via uri (e.g. { uri: 'assets/images/myImage.jpg' }). When building the app in XCode I just include the assets folder in the package.
From the CodePush documentation I gather that deploying the release folder should update all my assets. But it doesn't.
I downloaded the xcappdata via XCode and there you can see, that CodePush downloaded everything and stored it in /Library/Application Support/CodePush/[id]/release. But it still doesn't show up in the app.
Any ideas? Do I misunderstand the functionality of CodePush?
As you've seen, when you release a directory to the CodePush server via the CLI, it will round trip the entire contents of it to end-user's devices when they perform an update check/synchronization. That said, just because a file is in that update doesn't mean it will be useable unfortunately.
The behavior that you're seeing is actually a limitation of the way that the Image component resolves URIs in React Native. If you use the assets system to specify the "source" property (via a require("image.png") call), it will look for that file relative to the currently running JS bundle. This is how CodePush allows updating images, because as long as our plugin places the "assets" folder next to the JS bundle file on disk, the <Image> component will naturally find them.
However, when you specify an object with a URI (as you're doing) as the value of the "source" property, the Image component looks for that file relative to the binary on disk, and therefore, it will never look for it where it was placed by CodePush when you update them.
Because of this, CodePush only supports updating images which are loading via the require syntax. I'll make sure to update our docs to clarify that. Apologies for the confusion!

Running a packaged exe in the same folder as the installed firefox add-on

I have read this thread, and some other
How to run a local exe in my firefox extension
The problem is, at deployment and using firefox 4.0.1, if I install the .xpi extension, the xpi is put inside the \Profiles...\extensions as ****.xpi, which is a compressed format
All the solutions assume that the the extension is put in a folder, thus they are accessing the folder as is, which I cannot do
for example this guy says
//**** get profile folder path ****
var dsprops = Components.classes['#mozilla.org/file/directory_service;1']
.getService(Components.interfaces.nsIProperties);
var ProfilePath = dsprops.get("ProfD", Components.interfaces.nsIFile).path;
//**** initialize file ****
var file = Components.classes["#mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
file.initWithPath(ProfilePath);
//**** append each step in the path ****
file.append("extensions");
file.append("guid");
file.append("sample.exe");
guid in my case is installed as {f13b157f-b174-47e7-a34d-4815ddfdfeb8}.xpi which cannot be accessible this way
First of all, please do not locate files like this - you are making lots of assumptions about the directory structure of the Firefox profile, any of those could turn out false in a future Firefox version (or even in uncommon extension setup scenarios). See Reference a binary-component to js-ctypes instead for code to locate a file in your extension install directory, simply replace components/linux/myLib.so by sample.exe and execute uri.file.
Second: that's a scenario where packed XPI installation won't work unless you want to extract your executable into a temporary file before running it (which will be complicated). Windows doesn't support running executables from ZIP archives. So you need to add <em:unpack>true</em:unpack> to your extension's install.rdf to ensure that it is installed as an unpacked directory.
The best answer is to get flashgot Firefox addon , which contanins already executable inside , and is open source , and , study it , this is great way to observe how this actually works. Based on this , You can make as much as You wish addons with executable inside , or add entire program as FF addon. I hope this helps , even if this answer is rather than outdated.

Resources