Call C# from Js in WebView - Xamarin.Forms (iOS and Android) - javascript

I need a way to do c# calls to save some data (coming from js function in a webview) in my sqLite.
Thanks in advance!

My guess is that this won't be directly possible in Xamarin.Forms. You will probably need to write a custom renderer for each platform. Here is an article on custom renderers: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/. You will probably need to write one for the WebView class. Once you've done so, you'll be able to get at the native control and use its underlying functionality. I recommend trying the UWP one first as that will be the most straight forward.
This article explains how to intercept a JavaScript alert in UWP
https://code.msdn.microsoft.com/windowsapps/How-to-intercept-854d33da
But, you will also need to give more detail about what you actually want to do. What data do you want to pass back?

Related

Is it possible to retrieve data from parse.com using objective-c and show it in website?

I have an iOS app in which I use parse.com as backend service. Now, I hired someone to do a website interface using HTML and CSS. I want to share the same data between iOS app and website, I know parse.com offers me a few ways to do this, including creating a javaScriptapplication. The problem is, my programmer doesn't have any experience in JavaScript, nor do I.
My question is: Is it possible to use what I have (objective-c, xcode) as far as retrieving data from parse.com and showing on website? Even if I need to code something new, is it possible to use objective-c together with HTML and CSS?
Thanks.
Parse has several APIs, one of which is REST. Your web developer should use the REST API to get data from Parse
https://www.parse.com/docs/rest
If there is will there is way, but you'll be making something really specific to your use and will be non standard and will be immediately hard to maintain, I recommend that you hire another developer and do things properly using the technologies given to you by parse !. if the cost will be high now I can promise you it'll be much higher if you went the path you're going to now.
So my answer is:
Yes, everything is possible and no, don't do it ! :)
Edit: Added an example to a possible way to do it to actually answer OP's question.
Example case:
1-Create a simple Mac Application in Xcode that fetches data exactly like you do it on iOS, and store the needed data into a database of your choice on your server
2-You now have access to the data you needed from parse, but on a local mirror. you will need some tool to fetch that data though, I recommend a simple PHP script.
Note that this will require an OSX server to always be running to fetch that data, you'll also need of find a way to fetch data on demand when a user needs it Vs. polling at specified intervals, this will hardly scale and will be costly as I said.

How can I handle user data using QT Quick?

I am trying to develop an app for Ubuntu Touch. I am using QML integrated with JavaScript.
I know that it is a huge mess to read or write to files in JavaScript when it is embedded in a webpage, but this is not embedded in a webpage so it should be easier right? The Ubuntu documentation is pretty bad right now.
Does anyone know how I can get this done? I want to get it done without using c++ because using QML, JavaScript and c++ seems like just a big mess. If the only way to do it is using c++ then I guess thats what I will have to do, but I would like to find another way.
You will have to write a wrapper for QFile class that will be exposed to QML code. Here is an example how to do that. I'm not sure if it's outdated but it looks like it should work just fine.
The simplest way to handle data in your Ubuntu Touch app is to actually use SQLite (No surprise there). You can find a really good tutorial on using SQLite with Ubuntu Touch here:
https://askubuntu.com/questions/352157/how-to-use-a-sqlite-database-from-qml
It seems like this is the most efficient way to handle app data in Ubuntu Touch. If you want to be able to write to an actual file, you need to handle it using c++. Check out Kamil's answer for that.

Calling C++ from JavaScript / HTML using GTK+ Webkit Webview (and Qt WebKit bridge)

I am currently evaluating different approaches / solutions to call C++ functions from JavaScript code embedded in an HTML page. The application must be run on Ubuntu Server 12.04 LTS.
I am not an expert in Linux based development. This is the first time I am trying to work on something to interface between JavaScript and C++ code.
The C++ code basically resides in the .so files ( dynamic libraries) that would provide interface methods to access certain hardware and file system. The GUI needs to be in HTML and I am searching for different solutions that are possible that can call C++ from HTML. I searched and ended up deciding to try 2 approaches, both using the WebKit engine.
Approach 1: Using Qt 5.0.2 Webkit Bridge - the WebView control
The GUI framework will be on Qt framework, the main application window will contain a webview control that would run an HTML code which in turn contains the JavaScript code.
The interface between Web page and C++ is done using the addToJavaScriptWindowObject() function.
I created a sample application and tested this solution and it seems to works fine.
Approach 2: Using GTK+ WebKit WebView
I downloaded and installed the GTK 3.0 library.
I got the webkitgtk 2.0.1 and have installed it.
I have created a test application with GTK without webkit, it works well.
I am trying to create a webkit webview control using GTK.
When trying my Approach 1 with Qt, there was quite a good set of documentation and samples to do what I wanted to. But after starting with Approach 2 using GTK+, I feel am moving slower comparitively. I personally feel that the documentation part is not that straight forward for the kind of application I am trying to develop.
Other Approaches:
I also want to try to check if either using Applets (to call the .so files directly) or using the V8 JavaScript engine to interface between JavaScript and C++ are viable options(https://code.google.com/p/v8/)
I have tried the following resources:
http://webkitgtk.org/
http://www.webkit.org/
https://live.gnome.org/WebKitGtk/ProgrammingGuide/Tutorial
I want to know how exactly to do this interface part of calling a C++ functions (in .so files) when a button is clicked in a HTML web page containing JavaScript. What kind of signal am I supposed to look for. If I am using a WebkitWebview control, how do I map a button click to a c++ function?
Can someone point me to the right direction?
I would really appreciate your time and knowledge.
Regards.
Webkit GTK 2 changed significantly in terms of API's. So I am not sure if this will work with Webkit GTK 2. However this will definitely work in Webkit GTK 1.* versions. Don't know anything about QT.
For your need of connecting html view with C/C++ side of the world, you can use two approaches. Please take a look at function webkit_dom_event_target_add_event_listener. There is example at https://live.gnome.org/WebKitGtk/ProgrammingGuide/Cookbook
Another approach you can take is to use alert on click of the button and send a string as information. On C side, you can hookup the alert listener and parse the message and decide what needs to be done. I have written lot of code in python which takes this approach since call mentioned above is not exposed to python.
I agree documentation is bit sparse for webkit gtk. However if you know how you can acomplish something in javascript, usually you can map the javascript DOM management and event calls to C side. This includes generating elements dynamically, managing events such onclick etc. You just have to dig through the header files and find matching call.
If you need to use C++ code or native applications in your web application you can try to create a service over the C++ code and access it throught a REST (for example) API.
You can use a common web application framework (Spring/Java, Django/Python, etc.) to develop your web application and use Apache Thrift to interface your library.
the best solution for you is g-xml it is a good solution by GAMA but sorry it is not free.

how to use windowScriptObject on the iPhone?

Greetings!
I was wondering how I could use javascript code on an iPhone application I was developing. this tutorial illustrated how to use windowScriptObjects for Cocoa application. However, I have been unable to locate something similar for UIWebViews.
does this functionality actually exist in Cocoa touch? and if yes, could anyone point me to the right direction as to how I might start using it.
thank you once again
Like rpetrich said, this is Non-Public API so the windowScriptObject route might not be the best.
I did find this link though, which helped me a lot:
https://discussions.apple.com/message/7731057?messageID=7731057&#7731057
Basically, if you can keep your interactions between HTML and Objective-C entirely based on the user clicking links ( a href="" )
then all of this can be easily communicated between the two.
While it would be nice, I agree, to exchange variables and call methods at will, this already gives you a lot to work with. Hope that's useful!
This functionality is not exposed via a public API.

Communicating between two webviews with Javascript

In an application that has multiple webviews, is there any way to have the JavaScript in two separate webviews communicate with each other directly? I would really like to use JavaScript in one webview to control the contents of the other webview, but my bet is that each environment is completely isolated and that communication has to be serialized and sent through the webview controller.
Use <frameset>, <iframe> etc in the same web view to communicate between two pages.
Otherwise, there's no way to see outside of the environment (esp. for iPhoneOS since the whole WebKit framework is a private API.)
I'm looking to do the same thing and came across this thread in researching the problem. Haven't had a chance to model it yet, but looks like it's at least theoretically feasible by first using JavaScript to communicate with the Objective-C wrapper, and then sending that data over to the second WebView via a JavaScript call. Info on each of these two (independent) steps can be found here: http://www.codingventures.com/2008/12/using-uiwebview-to-render-svg-files/

Categories

Resources