Forráskód Böngészése

Updated to use Cordova 2.2.0 and made it pluginstall-able

Shazron Abdullah 13 éve
szülő
commit
104bc00060
12 módosított fájl, 323 hozzáadás és 309 törlés
  1. 1 0
      .gitignore
  2. 13 0
      LICENSE
  3. 54 54
      README.md
  4. 0 126
      SAiOSKeychainPlugin.js
  5. 18 12
      index.html
  6. 0 0
      example/master.css
  7. 28 0
      plugin.xml
  8. 31 0
      src/ios/CDVKeychain.h
  9. 120 0
      src/ios/CDVKeychain.m
  10. 4 25
      SAiOSKeychainPlugin.h
  11. 9 92
      SAiOSKeychainPlugin.m
  12. 45 0
      www/keychain.js

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+.DS_Store

+ 13 - 0
LICENSE

@@ -0,0 +1,13 @@
+Copyright [2012] [Shazron Abdullah]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.

+ 54 - 54
README.md

@@ -1,54 +1,54 @@
-# Cordova Keychain Plugin #
-by Shazron Abdullah
-
-## Adding the Plugin to your project ##
-
-Using this plugin requires [iOS Cordova](http://github.com/apache/incubator-cordova-ios) and Xcode 4.
-
-1. Make sure your Cordova Xcode project has been [updated for Cordova 1.6.0](https://github.com/apache/incubator-cordova-ios/blob/master/guides/Cordova%20Plugin%20Upgrade%20Guide.md)
-2. Add the .h and .m files to your Plugins folder in your project (as a Group "yellow folder" not a Reference "blue folder")
-3. Add the .js files to your "www" folder on disk, and add reference(s) to the .js files as <script> tags in your html file(s)
-4. In **Cordova.plist** (1.5.0 or greater) or **PhoneGap.plist** (1.4.1 or lesser), under the **Plugins** section, add an idential key and value of **"SAiOSKeychainPlugin"**
-5. Add the **"Security.framework"** to your project's Target, in the **Build Phase** tab - **Link Binary with Libraries**
-
-
-## RELEASE NOTES ##
-
-### 20120709 ###
-
-* Updated for Cordova
-
-### 20101105 ###
-* Initial release
-* See the .js file for API docs, and the KeychainPlugin-Host/www/index.html for sample code
-
-## BUGS AND CONTRIBUTIONS ##
-
-Patches welcome! Send a pull request. Since this is not a part of Cordova Core (which requires an Apache iCLA), this should be easier.
-
-Post issues in the [PhoneGap Google Groups](http://groups.google.com/group/phonegap), include in the subject heading - "KeychainPlugin" or on [Github](http://github.com/phonegap/phonegap-plugins/issues)
-(preferred)
-
-## LICENSE ##
-
-SFHFKeychainUtils code by:
-  Created by Buzz Andersen on 10/20/08.
-  Based partly on code by Jonathan Wight, Jon Crosby, and Mike Malone.
-  Copyright 2008 Sci-Fi Hi-Fi. All rights reserved.
-
-The rest:
-
-Copyright 2012 Shazron Abdullah
-
-   Licensed under the Apache License, Version 2.0 (the "License");
-   you may not use this file except in compliance with the License.
-   You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-
+Keychain Plugin for Apache Cordova
+=====================================
+created by Shazron Abdullah
+
+[Apache 2.0 License](http://www.apache.org/licenses/LICENSE-2.0.html) except for the SFHFKeychainUtils code that is under **src/ios/SFHFKeychainUtils**
+
+Follows the [Cordova Plugin spec](https://github.com/alunny/cordova-plugin-spec), so that it works with [Pluginstall](https://github.com/alunny/pluginstall), or you can install it manually below.
+ 
+1. Add the SFHFKeychainUtils files **(SFHFKeychainUtils.m, and SFHFKeychainUtils.h)** in Xcode (add as a group)
+2. Add the plugin files **(CDVKeychain.h, CDVKeychain.m)** in Xcode (add as a group)
+3. Add **keychain.js** to your **www** folder, and reference it in a script tag, after your cordova.js
+4. In __Cordova.plist__, under the **'Plugins'** key, add a new row: key is **"Keychain"** and the value is **"CDVKeychain"**
+5. Add the framework **"Security.framework"**
+    
+The plugin's JavaScript functions are called after getting the plugin object thus:
+ 
+        var kc = cordova.require("cordova/plugin/keychain");
+        kc.getForKey(win, fail, "some_key", "some_servicename");
+        
+See the **example** folder for example usage.
+
+        // Get a reference to the plugin first
+        var kc = cordova.require("cordova/plugin/keychain");
+
+        /*
+         Retrieves a value for a key and servicename.
+         
+         @param successCallback returns the value as the argument to the callback
+         @param failureCallback returns the error string as the argument to the callback
+         @param key the key to retrieve
+         @param servicename the servicename to use
+         */
+        kc.getForKey(successCallback, failureCallback, 'key', 'servicename');
+        
+        /*
+         Sets a value for a key and servicename.
+         
+         @param successCallback returns the value as the argument to the callback
+         @param failureCallback returns the error string as the argument to the callback
+         @param key the key to set
+         @param servicename the servicename to use
+         @param value the value to set
+         */
+        kc.setForKey(successCallback, failureCallback, 'key', 'servicename', 'value');
+        
+        /*
+         Removes a value for a key and servicename.
+         
+         @param successCallback returns the value as the argument to the callback
+         @param failureCallback returns the error string as the argument to the callback
+         @param key the key to remove
+         @param servicename the servicename to use
+         */
+        kc.removeForKey(successCallback, failureCallback, 'key', 'servicename');

+ 0 - 126
SAiOSKeychainPlugin.js

@@ -1,126 +0,0 @@
-// //////////////////////////////////////
-// Keychain PhoneGap Plugin
-// by Shazron Abdullah
-// Nov 5th 2010
-// 
-
-
-// ///////////////////
-(function(){
-// ///////////////////
-
-// get local ref to global PhoneGap/Cordova/cordova object for exec function
-var cordovaRef = window.PhoneGap || window.Cordova || window.cordova; // old to new fallbacks
-
-/**
- * Constructor
- */
-function SAiOSKeychainPlugin()
-{
-	this._getCallbacks = {};
-	this._setCallbacks = {};
-	this._removeCallbacks = {};
-}
-
-//MARK: Get
-
-SAiOSKeychainPlugin.prototype._onGetCallbackSuccess = function(key, value)
-{
-	if (this._getCallbacks[key] && this._getCallbacks[key].onSuccess) {
-		this._getCallbacks[key].onSuccess(key, value);
-	}
-	delete this._getCallbacks[key];
-}
-
-SAiOSKeychainPlugin.prototype._onGetCallbackFail = function(key, error)
-{
-	if (this._getCallbacks[key] && this._getCallbacks[key].onFail) {
-		this._getCallbacks[key].onFail(key, error);
-	}
-	delete this._getCallbacks[key];
-}
-
-
-SAiOSKeychainPlugin.prototype.getForKey = function(key, servicename, onSuccess, onFail)
-{
-	this._getCallbacks[key] = { onSuccess:onSuccess, onFail:onFail };
-	
-	cordovaRef.exec("SAiOSKeychainPlugin.getForKey", key, servicename);
-}
-
-//MARK: Set
-
-SAiOSKeychainPlugin.prototype._onSetCallbackSuccess = function(key)
-{
-	if (this._setCallbacks[key] && this._setCallbacks[key].onSuccess) {
-		this._setCallbacks[key].onSuccess(key);
-	}
-	delete this._setCallbacks[key];
-}
-
-SAiOSKeychainPlugin.prototype._onSetCallbackFail = function(key, error)
-{
-	if (this._setCallbacks[key] && this._setCallbacks[key].onFail) {
-		this._setCallbacks[key].onFail(key, error);
-	}
-	delete this._setCallbacks[key];
-}
-
-SAiOSKeychainPlugin.prototype.setForKey = function(key, value, servicename, onSuccess, onFail)
-{
-	this._setCallbacks[key] = { onSuccess:onSuccess, onFail:onFail };
-	
-	cordovaRef.exec("SAiOSKeychainPlugin.setForKey", key, value, servicename);
-}
-
-//MARK: Remove
-
-SAiOSKeychainPlugin.prototype._onRemoveCallbackSuccess = function(key)
-{
-	if (this._removeCallbacks[key] && this._removeCallbacks[key].onSuccess) {
-		this._removeCallbacks[key].onSuccess(key);
-	}
-	delete this._removeCallbacks[key];
-}
-
-SAiOSKeychainPlugin.prototype._onRemoveCallbackFail = function(key, error)
-{
-	if (this._removeCallbacks[key] && this._removeCallbacks[key].onFail) {
-		this._removeCallbacks[key].onFail(key, error);
-	}
-	delete this._removeCallbacks[key];
-}
-
-SAiOSKeychainPlugin.prototype.removeForKey = function(key, servicename, onSuccess, onFail)
-{
-	this._removeCallbacks[key] = { onSuccess:onSuccess, onFail:onFail };
-	
-	cordovaRef.exec("SAiOSKeychainPlugin.removeForKey", key, servicename);
-}
-
-//MARK: Install
-
-SAiOSKeychainPlugin.install = function()
-{
-	if ( !window.plugins ) {
-		window.plugins = {};
-	} 
-	if ( !window.plugins.keychain ) {
-		window.plugins.keychain = new SAiOSKeychainPlugin();
-	}
-}
-
-/**
- * Add to Cordova constructor
- */
-if (cordovaRef && cordovaRef.addConstructor) {
-	cordovaRef.addConstructor(SAiOSKeychainPlugin.install);
-} else {
-	console.log("Keychain Cordova Plugin could not be installed.");
-	return null;
-}
-
-// ///////////////////
-})();
-// ///////////////////
-

+ 18 - 12
index.html

@@ -6,14 +6,14 @@
 
     <meta http-equiv="Content-type" content="text/html; charset=utf-8">
 
-    <title>paypal-plugin-host</title>
+    <title></title>
 	
 	<!-- iPad/iPhone specific css below, add after your main css >
 	<link rel="stylesheet" media="only screen and (max-device-width: 1024px)" href="ipad.css" type="text/css" />		
 	<link rel="stylesheet" media="only screen and (max-device-width: 480px)" href="iphone.css" type="text/css" />		
 	-->
-	<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
-	<script type="text/javascript" charset="utf-8" src="SAiOSKeychainPlugin.js"></script>
+	<script type="text/javascript" charset="utf-8" src="cordova-2.2.0.js"></script>
+	<script type="text/javascript" charset="utf-8" src="keychain.js"></script>
     <script type="text/javascript" charset="utf-8">
 
 
@@ -45,48 +45,54 @@
 	
 	function onGet()
 	{
+       var kc = cordova.require("cordova/plugin/keychain");
+        
 	   var key = document.getElementById("keytoget").value;
 	   var servicename = document.getElementById("servicename").value
 	   
-	   var win = function(key, value) {
+	   var win = function(value) {
 			alert("GET SUCCESS - Key: " + key + " Value: " + value);
 	   };
-	   var fail = function(key, error) {
+	   var fail = function(error) {
 			alert("GET FAIL - Key: " + key + " Error: " + error);
 	   };
 	   
-	   window.plugins.keychain.getForKey(key, servicename, win, fail);
+	   kc.getForKey(win, fail, key, servicename);
 	}
 
 	function onSet()
 	{
+       var kc = cordova.require("cordova/plugin/keychain");
+
 	   var key = document.getElementById("keytoset").value;
 	   var value = document.getElementById("valuetoset").value;
 	   var servicename = document.getElementById("servicename").value;
 	   
-	   var win = function(key) {
+	   var win = function() {
 			alert("SET SUCCESS - Key: " + key);
 	   };
-	   var fail = function(key, error) {
+	   var fail = function(error) {
 			alert("SET FAIL - Key: " + key + " Error: " + error);
 	   };
 	   
-	   window.plugins.keychain.setForKey(key, value, servicename, win, fail);
+	   kc.setForKey(win, fail, key, servicename, value);
 	}
 
 	function onRemove()
 	{
+       var kc = cordova.require("cordova/plugin/keychain");
+        
 	   var key = document.getElementById("keytoremove").value;
 	   var servicename = document.getElementById("servicename").value
 	   
-	   var win = function(key) {
+	   var win = function() {
 			alert("REMOVE SUCCESS - Key: " + key);
 	   };
-	   var fail = function(key, error) {
+	   var fail = function(error) {
 			alert("REMOVE FAIL - Key: " + key + " Error: " + error);
 	   };
 	   
-	   window.plugins.keychain.removeForKey(key, servicename, win, fail);
+	   kc.removeForKey(win, fail, key, servicename);
 	}
     
     </script>

master.css → example/master.css


+ 28 - 0
plugin.xml

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
+    id="com.phonegap.plugins.keychain"
+    version="1.0.0">
+
+    <name>iOS KeyChain</name>
+	
+	<engines>
+	    <engine name="cordova" version="2.2.0" />
+	</engines>
+	
+    <asset src="www/keychain.js" target="keychain.js" />
+
+    <!-- ios -->
+    <platform name="ios">
+        <plugins-plist key="Keychain"
+                    string="CDVKeychain" />
+
+        <!-- Note: the ios src is based off src/ios implicitly --> 
+        <header-file src="CDVKeychain.h" />
+        <header-file src="SFHFKeychainUtils/SFHFKeychainUtils.h"/>
+        
+        <source-file src="CDVKeychain.m" />
+        <source-file src="SFHFKeychainUtils/SFHFKeychainUtils.m" />
+        
+        <framework src="Security.framework" />
+    </platform>
+</plugin>

+ 31 - 0
src/ios/CDVKeychain.h

@@ -0,0 +1,31 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+ 
+#import <UIKit/UIKit.h>
+#import <Foundation/Foundation.h>
+#import <Cordova/CDVPlugin.h>
+
+@interface CDVKeychain : CDVPlugin {
+}
+
+- (void) getForKey:(CDVInvokedUrlCommand*)command;
+- (void) setForKey:(CDVInvokedUrlCommand*)command;
+- (void) removeForKey:(CDVInvokedUrlCommand*)command;
+
+@end

+ 120 - 0
src/ios/CDVKeychain.m

@@ -0,0 +1,120 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import "CDVKeychain.h"
+#import "SFHFKeychainUtils.h"
+
+@implementation CDVKeychain
+
+- (CDVPlugin*) initWithWebView:(UIWebView*)theWebView
+{
+    self = (CDVKeychain*)[super initWithWebView:(UIWebView*)theWebView];
+    if (self) {
+		// initialization here
+    }
+    return self;
+}
+
+- (void) getForKey:(CDVInvokedUrlCommand*)command
+{
+    NSArray* arguments = command.arguments;
+    CDVPluginResult* pluginResult = nil;
+    
+    if ([arguments count] >= 2)
+    {
+        NSString* key = [arguments objectAtIndex:0];
+        NSString* serviceName = [arguments objectAtIndex:1];
+        NSError* error = nil;
+        
+        NSString* value = [SFHFKeychainUtils getPasswordForUsername:key andServiceName:serviceName error:&error];
+        if (error == nil && value != nil) {
+            pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:value];
+        } else {
+            pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR
+                                             messageAsString:[NSString stringWithFormat:@"error retrieving value for key '%@' : %@", key, [error localizedDescription]]];
+        }
+    }
+    else
+    {
+        pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR
+                                         messageAsString:@"incorrect number of arguments for getForkey"];
+    }
+    
+    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+}
+
+- (void) setForKey:(CDVInvokedUrlCommand*)command
+{
+    NSArray* arguments = command.arguments;
+    CDVPluginResult* pluginResult = nil;
+    
+    if ([arguments count] >= 3)
+    {
+        NSString* key = [arguments objectAtIndex:0];
+        NSString* serviceName = [arguments objectAtIndex:1];
+        NSString* value = [arguments objectAtIndex:2];
+        NSError* error = nil;
+        
+        BOOL stored = [SFHFKeychainUtils storeUsername:key andPassword:value forServiceName:serviceName updateExisting:YES error:&error];
+        if (stored && error == nil) {
+            pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
+        } else {
+            pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[error localizedDescription]];
+        }
+    }
+    else
+    {
+        pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR
+                                         messageAsString:@"incorrect number of arguments for setForKey"];
+    }
+
+    
+    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+}
+
+- (void) removeForKey:(CDVInvokedUrlCommand*)command
+{
+    NSArray* arguments = command.arguments;
+    CDVPluginResult* pluginResult = nil;
+    
+    if ([arguments count] >= 2)
+    {
+        NSString* key = [arguments objectAtIndex:0];
+        NSString* serviceName = [arguments objectAtIndex:1];
+        NSError* error = nil;
+        
+        BOOL deleted = [SFHFKeychainUtils deleteItemForUsername:key andServiceName:serviceName error:&error];
+        if (deleted && error == nil) {
+            pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
+        } else {
+            pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[error localizedDescription]];
+        }
+    }
+    else
+    {
+        pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR
+                                         messageAsString:@"incorrect number of arguments for removeForKey"];
+    }
+    
+    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+}
+
+
+@end
+

+ 4 - 25
SAiOSKeychainPlugin.h

@@ -1,28 +1,4 @@
 //
-//  SAiOSPaypalPlugin.h
-//  Keychain Plugin for Cordova
-//
-//  Created by shazron on 10-11-05.
-//  Copyright 2012 Shazron Abdullah. All rights reserved.
-
-#import <UIKit/UIKit.h>
-#import <Foundation/Foundation.h>
-#ifdef CORDOVA_FRAMEWORK
-#import <Cordova/CDVPlugin.h>
-#else
-#import "CDVPlugin.h"
-#endif
-
-@interface SAiOSKeychainPlugin : CDVPlugin {
-}
-
-- (void) getForKey:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
-- (void) setForKey:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
-- (void) removeForKey:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
-
-@end
-
-//
 //  SFHFKeychainUtils.h
 //
 //  Created by Buzz Andersen on 10/20/08.
@@ -51,8 +27,11 @@
 //  OTHER DEALINGS IN THE SOFTWARE.
 //
 
-@interface SFHFKeychainUtils : NSObject {
+#import <UIKit/UIKit.h>
+
 
+@interface SFHFKeychainUtils : NSObject {
+  
 }
 
 + (NSString *) getPasswordForUsername: (NSString *) username andServiceName: (NSString *) serviceName error: (NSError **) error;

+ 9 - 92
SAiOSKeychainPlugin.m

@@ -1,92 +1,4 @@
 //
-//  SAiOSPaypalPlugin.m
-//  Cordova Plugin for Cordova
-//
-//  Created by shazron on 10-11-05.
-//  Copyright 2010 Shazron Abdullah. All rights reserved.
-
-#import "SAiOSKeychainPlugin.h"
-
-@implementation SAiOSKeychainPlugin
-
--(CDVPlugin*) initWithWebView:(UIWebView*)theWebView
-{
-    self = (SAiOSKeychainPlugin*)[super initWithWebView:(UIWebView*)theWebView];
-    if (self) {
-		// initialization here
-    }
-    return self;
-}
-
-- (void) getForKey:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
-{
-	int argc = [arguments count];
-	if (argc < 2) {
-		return;
-	}
-	
-	NSString* key = [arguments objectAtIndex:0];
-	NSString* serviceName = [arguments objectAtIndex:1];
-	NSError* error = nil;
-	
-	NSString* value = [SFHFKeychainUtils getPasswordForUsername:key andServiceName:serviceName error:&error];
-	if (error == nil && value != nil) {
-		NSString* jsCallback = [NSString stringWithFormat:@"window.plugins.keychain._onGetCallbackSuccess(\"%@\", \"%@\");", key, value];
-		[super writeJavascript:jsCallback];
-	} else {
-		NSString* jsCallback = [NSString stringWithFormat:@"window.plugins.keychain._onGetCallbackFail(\"%@\", \"%@\");", key, [error localizedDescription]];
-		[super writeJavascript:jsCallback];
-	}
-}
-
-- (void) setForKey:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
-{
-	int argc = [arguments count];
-	if (argc < 3) {
-		return;
-	}
-	
-	NSString* key = [arguments objectAtIndex:0];
-	NSString* value = [arguments objectAtIndex:1];
-	NSString* serviceName = [arguments objectAtIndex:2];
-	NSError* error = nil;
-	
-	BOOL stored = [SFHFKeychainUtils storeUsername:key andPassword:value forServiceName:serviceName updateExisting:YES error:&error];
-	if (stored) {
-		NSString* jsCallback = [NSString stringWithFormat:@"window.plugins.keychain._onSetCallbackSuccess(\"%@\");", key];
-		[super writeJavascript:jsCallback];
-	} else {
-		NSString* jsCallback = [NSString stringWithFormat:@"window.plugins.keychain._onSetCallbackFail(\"%@\", \"%@\");", key, [error localizedDescription]];
-		[super writeJavascript:jsCallback];
-	}
-}
-
-- (void) removeForKey:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
-{	
-	int argc = [arguments count];
-	if (argc < 2) {
-		return;
-	}
-	
-	NSString* key = [arguments objectAtIndex:0];
-	NSString* serviceName = [arguments objectAtIndex:1];
-	NSError* error = nil;
-	
-	BOOL deleted = [SFHFKeychainUtils deleteItemForUsername:key andServiceName:serviceName error:&error];
-	if (deleted) {
-		NSString* jsCallback = [NSString stringWithFormat:@"window.plugins.keychain._onRemoveCallbackSuccess(\"%@\");", key];
-		[super writeJavascript:jsCallback];
-	} else {
-		NSString* jsCallback = [NSString stringWithFormat:@"window.plugins.keychain._onRemoveCallbackFail(\"%@\", \"%@\");", key, [error localizedDescription]];
-		[super writeJavascript:jsCallback];
-	}
-}
-
-
-@end
-
-
-//
 //  SFHFKeychainUtils.m
 //
 //  Created by Buzz Andersen on 10/20/08.
@@ -115,6 +27,7 @@
 //  OTHER DEALINGS IN THE SOFTWARE.
 //
 
+#import "SFHFKeychainUtils.h"
 #import <Security/Security.h>
 
 static NSString *SFHFKeychainUtilsErrorDomain = @"SFHFKeychainUtilsErrorDomain";
@@ -472,10 +385,12 @@ static NSString *SFHFKeychainUtilsErrorDomain = @"SFHFKeychainUtilsErrorDomain";
 		status = SecItemAdd((CFDictionaryRef) query, NULL);
 	}
 	
-	if (error != nil && status != noErr) 
+	if (status != noErr) 
   {
 		// Something went wrong with adding the new item. Return the Keychain error code.
-		*error = [NSError errorWithDomain: SFHFKeychainUtilsErrorDomain code: status userInfo: nil];
+		if (error != nil) {
+			*error = [NSError errorWithDomain: SFHFKeychainUtilsErrorDomain code: status userInfo: nil];
+		}
     
     return NO;
 	}
@@ -506,9 +421,11 @@ static NSString *SFHFKeychainUtilsErrorDomain = @"SFHFKeychainUtilsErrorDomain";
 	
 	OSStatus status = SecItemDelete((CFDictionaryRef) query);
 	
-	if (error != nil && status != noErr) 
+	if (status != noErr) 
   {
-		*error = [NSError errorWithDomain: SFHFKeychainUtilsErrorDomain code: status userInfo: nil];		
+	  if (error != nil) {
+		  *error = [NSError errorWithDomain: SFHFKeychainUtilsErrorDomain code: status userInfo: nil];
+	  }
     
     return NO;
 	}

+ 45 - 0
www/keychain.js

@@ -0,0 +1,45 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+ 
+ cordova.define("cordova/plugin/keychain", function(require, exports, module) {
+ 	var exec = require('cordova/exec');
+
+	var Keychain = function() {
+	    this.serviceName = "Keychain";
+	};
+
+    Keychain.prototype.getForKey = function(successCallback, failureCallback, key, servicename)
+    {
+        exec(successCallback, failureCallback, this.serviceName, "getForKey", [key, servicename]);
+    }
+    
+    Keychain.prototype.setForKey = function(successCallback, failureCallback, key, servicename, value)
+    {
+        exec(successCallback, failureCallback, this.serviceName, "setForKey", [key, servicename, value]);
+    }
+    
+    Keychain.prototype.removeForKey = function(successCallback, failureCallback, key, servicename)
+    {
+        exec(successCallback, failureCallback, this.serviceName, "removeForKey", [key, servicename]);
+    }
+
+ 	var keychain = new Keychain();
+ 	module.exports = keychain;
+
+ });