Windows Phone 8 - Implementing Apache Cordova plugin
In some cases, developers of a MobileFirst application might have to use a specific third-party native library or a device function that is not yet available in Apache Cordova.
This tutorial demonstrates how to create and integrate a simple Apache Cordova plug-in for Windows Phone 8, in the following topics:
- Creating a plug-in
- Declaring a plug-in
- Implementing the C# code of a Cordova plug-in
- Sample application
Note: In Cordova-based applications, developers must check for the
deviceready event before they use the Cordova API set. In a MobileFirst application, however, this check is done internally.
Instead of implementing this check, you can place implementation code in the
wlCommonInit() function in the
Creating a plug-in
- Declare the plug-in in the
- Use the
- Create the plug-in class that will run natively in Windows Phone 8.
Declaring a plug-in
You must declare the plug-in in the project, so that Cordova can detect it.
To declare the plug-in, add a reference to the
config.xml file, located in the native folder of the Windows Phone 8 environment.
cordova.exec()method to call the Cordova plug-in:
sayHelloSuccess- Success callback
sayHelloFailure- Failure callback
SayHelloPlugin- Plug-in name as declared in the
sayHello- Action name
[name]- Parameters array
The plug-in calls the
Implementing the C# code of a Cordova plug-in
- Create a new C# class.
- Add the new class to your project namespace and add the required import statements.
SayHelloPlugin class and the