I'm using cordova/phonegap to make a windows phone app, i'm trying to call a script from C# when an event fires.
Is there anyway to do this?
here's my class so far.
public void register(string options)
{
// This is executed asynchronously
if (!TryFindChannel())
DoConnect();
}
void httpChannel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)
{
// Finished asynchronous task in "register" method
Trace("Channel opened. Got Uri:\n" + httpChannel.ChannelUri.ToString());
SaveChannelInfo();
Trace("Subscribing to channel events");
SubscribeToService();
SubscribeToNotifications();
// SEND CHANNEL URI TO JAVASCRIPT
}
I found a solution, admittedly not the best one but works for me.
I created a singleton class called WebViewHandler which looks like this
Then I set the webview in the constructor on the HomePage like so:
Once the WebView is set I can then call InvokeScript from any other class:
You could use DispatchCommandResult(); as outlined in the cordova documents. That way you can call the c# method, send whatever you need in the callback, and then just execute the javascript from within javascript.
Try this example :
Try:
InvokeScript
executes a scripting function defined in the currently loaded document, and passes the function an array of string parameters.http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff402838%28v=vs.105%29.aspx
Obviously you have to have the
JavaScript
function defined in the loaded document.Depending on your view it may work like this: