incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [5/5] docs commit: wp7 plugin guide wio
Date Wed, 25 Jul 2012 23:03:43 GMT
wp7 plugin guide wio


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-docs/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-docs/commit/5ff24116
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-docs/tree/5ff24116
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-docs/diff/5ff24116

Branch: refs/heads/master
Commit: 5ff24116983ee7944ac523083de7bf3cbfc460fd
Parents: 0b15419
Author: Jesse MacFadyen <purplecabbage@gmail.com>
Authored: Wed Jul 25 13:04:30 2012 -0700
Committer: Jesse MacFadyen <purplecabbage@gmail.com>
Committed: Wed Jul 25 13:04:30 2012 -0700

----------------------------------------------------------------------
 .../plugin-development/windows-phone/index.md      |   88 ++++++++++++++-
 1 files changed, 87 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-docs/blob/5ff24116/docs/en/edge/guide/plugin-development/windows-phone/index.md
----------------------------------------------------------------------
diff --git a/docs/en/edge/guide/plugin-development/windows-phone/index.md b/docs/en/edge/guide/plugin-development/windows-phone/index.md
index 0f74950..d8c5d40 100644
--- a/docs/en/edge/guide/plugin-development/windows-phone/index.md
+++ b/docs/en/edge/guide/plugin-development/windows-phone/index.md
@@ -20,4 +20,90 @@ license: Licensed to the Apache Software Foundation (ASF) under one
 Developing a Plugin on Windows Phone
 ====================================
 
-Coming soon...
+Writing a plugin for Cordova on Windows Phone requires a basic understanding of the architecture
of Cordova. Cordova-WP7 consists of a WebBrowser which hosts the application javascript code
and manages native API calls. There is a BaseCommand class in C# which you can extend, and
it comes with the majority of the 'plumbing' built for you already.
+
+
+
+
+
+Select your project, and right click choose 'Add -> New Item ...'
+- Preferably add it to the 'Plugins' folder, but it is up to you
+Select 'Class' and name it Echo.cs
+The name of this class must EXACTLY match what you call into cordova.exec(win,fail,"Echo",...)
+
+
+
+Include the base classes implementation :
+using WP7CordovaClassLib.Cordova;
+using WP7CordovaClassLib.Cordova.Commands;
+using WP7CordovaClassLib.Cordova.JSON;
+
+Extend your class from BaseCommand 
+
+The default namespace for unqualified commands is :
+namespace Cordova.Extension.Commands
+
+If you would like to use your own namespace, you will need to make a fully qualified call
to cordova.exec
+C#
+namespace com.mydomain.cordovaExtensions {...}
+JS
+codova.exec(win,fail,"com.mydomain.cordovaExtensions.Echo",...);
+
+Passing results from C# to JS 
+===
+
+DispatchCommandResult(); // calls back with an empty plugin result, considered a success
callback
+
+If you need to signal that an error has occured, you can call DispatchCommandResult with
a PluginResult object.
+DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Echo signalled an error"));
+
+Interpretting your arguments
+===
+
+The data received by your plugin method is a string value, but in actuallality we our intention
was to pass an array of strings.  Looking back at our JS call to cordova.exec, we see we passed
[str]
+cordova.exec( win, fail, "Echo", "echo", ["input string"]); 
+
+If we inspect the options string passed in to our Echo.echo method, we will see that the
value is actually:
+"[\"input string\"]"
+
+All javascript exec arguments are JSON encoded before being passed into C#.
+
+If we want to treat this as the string we were expecting, we need to decode it.
+We can use simple JSON deserialization.
+
+string optVal = JsonHelper.Deserialize<string[]>(options)[0];
+// optVal now has the value of "input string"
+
+Handling serialization errors
+===
+
+When interpretting your arguments, it is a good idea to use a try/catch block in case we
have bad input.
+This is a pattern used throughout the Cordova C# code :
+
+
+   string optVal = null;
+
+   try 
+   {
+      optVal = JsonHelper.Deserialize<string[]>(options)[0];
+   }
+   catch(Exception)
+   {
+      // simply catch the exception, we will handle null values and exceptions together
+   }
+
+   if(optVal == null)
+   {
+      DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
+   }
+   else
+   {
+      // ... continue on to do our work
+   }
+
+
+
+
+
+
+


Mime
View raw message