From a71857d85ade7c3d5b2ce86d6b39e95f14104b33 Mon Sep 17 00:00:00 2001 From: Andrew Thorp Date: Fri, 13 Apr 2012 16:10:02 -0400 Subject: [PATCH 1/6] Unique Identifier initial commit for PhoneGap 1.4.1 --- iOS/UniqueIdentifier/PGUniqueIdentifier.h | 35 ++++++++++++ iOS/UniqueIdentifier/PGUniqueIdentifier.m | 67 +++++++++++++++++++++++ iOS/UniqueIdentifier/README.md | 17 ++++++ iOS/UniqueIdentifier/UniqueIdentifier.js | 11 ++++ 4 files changed, 130 insertions(+) create mode 100644 iOS/UniqueIdentifier/PGUniqueIdentifier.h create mode 100644 iOS/UniqueIdentifier/PGUniqueIdentifier.m create mode 100644 iOS/UniqueIdentifier/README.md create mode 100644 iOS/UniqueIdentifier/UniqueIdentifier.js diff --git a/iOS/UniqueIdentifier/PGUniqueIdentifier.h b/iOS/UniqueIdentifier/PGUniqueIdentifier.h new file mode 100644 index 0000000..a7c98fb --- /dev/null +++ b/iOS/UniqueIdentifier/PGUniqueIdentifier.h @@ -0,0 +1,35 @@ +// +// PGUniqueIdentifier.h +// UniqueIdentifierPlugin +// +// Created by Andrew Thorp on 4/13/12 +// +// +// THIS SOFTWARE IS PROVIDED BY THE ANDREW THORP "AS IS" AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +// EVENT SHALL ANDREW TRICE OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// + +#import +#import + +@interface PGUniqueIdentifier : PGPlugin { + NSString* callbackId; + NSString* uuidString; + CFUUIDRef uuid; +} + +@property (nonatomic, copy) NSString* callbackID; + +//Public Instance Method (visible in phonegap API) +- (void) generateUUID:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options; +- (void) getUUID:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options; + +@end \ No newline at end of file diff --git a/iOS/UniqueIdentifier/PGUniqueIdentifier.m b/iOS/UniqueIdentifier/PGUniqueIdentifier.m new file mode 100644 index 0000000..3285c5e --- /dev/null +++ b/iOS/UniqueIdentifier/PGUniqueIdentifier.m @@ -0,0 +1,67 @@ +// +// PGUniqueIdentifier.m +// UniqueIdentifierPlugin +// +// Created by Andrew Thorp on 4/13/12 +// +// +// THIS SOFTWARE IS PROVIDED BY THE ANDREW THORP "AS IS" AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +// EVENT SHALL ANDREW TRICE OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// + +#import "PGUniqueIdentifier.h" +#define UUID_USER_DEFAULTS_KEY @"UUID" + +@implementation PGUniqueIdentifier + +@synthesize callbackID; + +NSString* UNIQUE_IDENTIFIER_OK = @"OK"; +NSString* UNIQUE_IDENTIFIER_ERROR = @"ERROR"; + +- (void) generateUUID:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options +{ + self.callbackID = [arguments pop]; + uuid = CFUUIDCreate(NULL); + if (uuid) { + uuidString = (NSString *)CFUUIDCreateString(NULL, uuid); + CFRelease(uuid); + } + + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + if ([defaults stringForKey:UUID_USER_DEFAULTS_KEY] == nil) { + [defaults setObject:uuidString forKey:UUID_USER_DEFAULTS_KEY]; + [defaults synchronize]; + } + + NSString *uniqueIdentifier = [defaults stringForKey:UUID_USER_DEFAULTS_KEY]; + + PluginResult* pluginResult = [PluginResult resultWithStatus:PGCommandStatus_OK messageAsString: uniqueIdentifier]; + [self writeJavascript: [pluginResult toSuccessCallbackString:self.callbackID]]; +} + +- (void) getUUID:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options +{ + self.callbackID = [arguments pop]; + PluginResult* pluginResult; + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + + if ([defaults stringForKey:UUID_USER_DEFAULTS_KEY] == nil){ + pluginResult = [PluginResult resultWithStatus:PGCommandStatus_ERROR messageAsString: UNIQUE_IDENTIFIER_ERROR]; + [self writeJavascript: [pluginResult toErrorCallbackString:self.callbackID]]; + } else { + NSString *uniqueIdentifier = [defaults stringForKey:UUID_USER_DEFAULTS_KEY]; + pluginResult = [PluginResult resultWithStatus:PGCommandStatus_OK messageAsString: uniqueIdentifier]; + [self writeJavascript: [pluginResult toSuccessCallbackString:self.callbackID]]; + } +} + +@end \ No newline at end of file diff --git a/iOS/UniqueIdentifier/README.md b/iOS/UniqueIdentifier/README.md new file mode 100644 index 0000000..71925d1 --- /dev/null +++ b/iOS/UniqueIdentifier/README.md @@ -0,0 +1,17 @@ +# Unique Identifier support for iOS applications + +_by Created by `Andrew Thorp`_ + +Usage: + + // To GENERATE a Unique ID + PGUniqueIdentifier.generateUUID(function(result){ + // result will be the new UUID or the UUID that is stored in this apps NSDefaults + }); + + // To GET the Unique ID + PGUniqueIdentifier.getUUID(function(result){ + // result will be the UUID stored in this apps NSDefaults + }, function(error){ + // If a UUID has not yet been generated, you will receive the error "ERROR". + }); \ No newline at end of file diff --git a/iOS/UniqueIdentifier/UniqueIdentifier.js b/iOS/UniqueIdentifier/UniqueIdentifier.js new file mode 100644 index 0000000..8854214 --- /dev/null +++ b/iOS/UniqueIdentifier/UniqueIdentifier.js @@ -0,0 +1,11 @@ +var PGUniqueIdentifier = { + + generateUUID: function(success, fail) { + return PhoneGap.exec(success, fail, "PGUniqueIdentifier", "generateUUID", []); + }, + + getUUID: function(success, fail) { + return PhoneGap.exec(success, fail, "PGUniqueIdentifier", "getUUID", []); + } + +}; \ No newline at end of file From adf990f56598702a3f1329a59d7955824cb04fb7 Mon Sep 17 00:00:00 2001 From: Andrew Thorp Date: Fri, 13 Apr 2012 16:10:33 -0400 Subject: [PATCH 2/6] fixed readme --- iOS/UniqueIdentifier/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iOS/UniqueIdentifier/README.md b/iOS/UniqueIdentifier/README.md index 71925d1..ebbce3d 100644 --- a/iOS/UniqueIdentifier/README.md +++ b/iOS/UniqueIdentifier/README.md @@ -1,6 +1,6 @@ # Unique Identifier support for iOS applications -_by Created by `Andrew Thorp`_ +_Created by `Andrew Thorp`_ Usage: From 79773223716adad7b5a8727476931369328055ee Mon Sep 17 00:00:00 2001 From: Andrew Thorp Date: Tue, 8 May 2012 11:56:12 -0400 Subject: [PATCH 3/6] moved phonegap version to /iPhone --- .../UniqueIdentifier/PGUniqueIdentifier.h | 35 ++++++++++ .../UniqueIdentifier/PGUniqueIdentifier.m | 67 +++++++++++++++++++ .../UniqueIdentifier/README.md | 17 +++++ .../UniqueIdentifier/UniqueIdentifier.js | 11 +++ 4 files changed, 130 insertions(+) create mode 100644 iPhone/UniqueIdentifier/UniqueIdentifier/PGUniqueIdentifier.h create mode 100644 iPhone/UniqueIdentifier/UniqueIdentifier/PGUniqueIdentifier.m create mode 100644 iPhone/UniqueIdentifier/UniqueIdentifier/README.md create mode 100644 iPhone/UniqueIdentifier/UniqueIdentifier/UniqueIdentifier.js diff --git a/iPhone/UniqueIdentifier/UniqueIdentifier/PGUniqueIdentifier.h b/iPhone/UniqueIdentifier/UniqueIdentifier/PGUniqueIdentifier.h new file mode 100644 index 0000000..a7c98fb --- /dev/null +++ b/iPhone/UniqueIdentifier/UniqueIdentifier/PGUniqueIdentifier.h @@ -0,0 +1,35 @@ +// +// PGUniqueIdentifier.h +// UniqueIdentifierPlugin +// +// Created by Andrew Thorp on 4/13/12 +// +// +// THIS SOFTWARE IS PROVIDED BY THE ANDREW THORP "AS IS" AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +// EVENT SHALL ANDREW TRICE OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// + +#import +#import + +@interface PGUniqueIdentifier : PGPlugin { + NSString* callbackId; + NSString* uuidString; + CFUUIDRef uuid; +} + +@property (nonatomic, copy) NSString* callbackID; + +//Public Instance Method (visible in phonegap API) +- (void) generateUUID:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options; +- (void) getUUID:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options; + +@end \ No newline at end of file diff --git a/iPhone/UniqueIdentifier/UniqueIdentifier/PGUniqueIdentifier.m b/iPhone/UniqueIdentifier/UniqueIdentifier/PGUniqueIdentifier.m new file mode 100644 index 0000000..3285c5e --- /dev/null +++ b/iPhone/UniqueIdentifier/UniqueIdentifier/PGUniqueIdentifier.m @@ -0,0 +1,67 @@ +// +// PGUniqueIdentifier.m +// UniqueIdentifierPlugin +// +// Created by Andrew Thorp on 4/13/12 +// +// +// THIS SOFTWARE IS PROVIDED BY THE ANDREW THORP "AS IS" AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +// EVENT SHALL ANDREW TRICE OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// + +#import "PGUniqueIdentifier.h" +#define UUID_USER_DEFAULTS_KEY @"UUID" + +@implementation PGUniqueIdentifier + +@synthesize callbackID; + +NSString* UNIQUE_IDENTIFIER_OK = @"OK"; +NSString* UNIQUE_IDENTIFIER_ERROR = @"ERROR"; + +- (void) generateUUID:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options +{ + self.callbackID = [arguments pop]; + uuid = CFUUIDCreate(NULL); + if (uuid) { + uuidString = (NSString *)CFUUIDCreateString(NULL, uuid); + CFRelease(uuid); + } + + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + if ([defaults stringForKey:UUID_USER_DEFAULTS_KEY] == nil) { + [defaults setObject:uuidString forKey:UUID_USER_DEFAULTS_KEY]; + [defaults synchronize]; + } + + NSString *uniqueIdentifier = [defaults stringForKey:UUID_USER_DEFAULTS_KEY]; + + PluginResult* pluginResult = [PluginResult resultWithStatus:PGCommandStatus_OK messageAsString: uniqueIdentifier]; + [self writeJavascript: [pluginResult toSuccessCallbackString:self.callbackID]]; +} + +- (void) getUUID:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options +{ + self.callbackID = [arguments pop]; + PluginResult* pluginResult; + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + + if ([defaults stringForKey:UUID_USER_DEFAULTS_KEY] == nil){ + pluginResult = [PluginResult resultWithStatus:PGCommandStatus_ERROR messageAsString: UNIQUE_IDENTIFIER_ERROR]; + [self writeJavascript: [pluginResult toErrorCallbackString:self.callbackID]]; + } else { + NSString *uniqueIdentifier = [defaults stringForKey:UUID_USER_DEFAULTS_KEY]; + pluginResult = [PluginResult resultWithStatus:PGCommandStatus_OK messageAsString: uniqueIdentifier]; + [self writeJavascript: [pluginResult toSuccessCallbackString:self.callbackID]]; + } +} + +@end \ No newline at end of file diff --git a/iPhone/UniqueIdentifier/UniqueIdentifier/README.md b/iPhone/UniqueIdentifier/UniqueIdentifier/README.md new file mode 100644 index 0000000..ebbce3d --- /dev/null +++ b/iPhone/UniqueIdentifier/UniqueIdentifier/README.md @@ -0,0 +1,17 @@ +# Unique Identifier support for iOS applications + +_Created by `Andrew Thorp`_ + +Usage: + + // To GENERATE a Unique ID + PGUniqueIdentifier.generateUUID(function(result){ + // result will be the new UUID or the UUID that is stored in this apps NSDefaults + }); + + // To GET the Unique ID + PGUniqueIdentifier.getUUID(function(result){ + // result will be the UUID stored in this apps NSDefaults + }, function(error){ + // If a UUID has not yet been generated, you will receive the error "ERROR". + }); \ No newline at end of file diff --git a/iPhone/UniqueIdentifier/UniqueIdentifier/UniqueIdentifier.js b/iPhone/UniqueIdentifier/UniqueIdentifier/UniqueIdentifier.js new file mode 100644 index 0000000..8854214 --- /dev/null +++ b/iPhone/UniqueIdentifier/UniqueIdentifier/UniqueIdentifier.js @@ -0,0 +1,11 @@ +var PGUniqueIdentifier = { + + generateUUID: function(success, fail) { + return PhoneGap.exec(success, fail, "PGUniqueIdentifier", "generateUUID", []); + }, + + getUUID: function(success, fail) { + return PhoneGap.exec(success, fail, "PGUniqueIdentifier", "getUUID", []); + } + +}; \ No newline at end of file From eaced0d07dd18d3b79bf5e4ec021e9a83010b0e7 Mon Sep 17 00:00:00 2001 From: Andrew Thorp Date: Tue, 8 May 2012 11:56:22 -0400 Subject: [PATCH 4/6] upgraded /iOS version to Cordova --- ...GUniqueIdentifier.h => UniqueIdentifier.h} | 13 +++-- iOS/UniqueIdentifier/UniqueIdentifier.js | 51 +++++++++++++++---- ...GUniqueIdentifier.m => UniqueIdentifier.m} | 22 ++++---- 3 files changed, 62 insertions(+), 24 deletions(-) rename iOS/UniqueIdentifier/{PGUniqueIdentifier.h => UniqueIdentifier.h} (87%) rename iOS/UniqueIdentifier/{PGUniqueIdentifier.m => UniqueIdentifier.m} (80%) diff --git a/iOS/UniqueIdentifier/PGUniqueIdentifier.h b/iOS/UniqueIdentifier/UniqueIdentifier.h similarity index 87% rename from iOS/UniqueIdentifier/PGUniqueIdentifier.h rename to iOS/UniqueIdentifier/UniqueIdentifier.h index a7c98fb..c0d8683 100644 --- a/iOS/UniqueIdentifier/PGUniqueIdentifier.h +++ b/iOS/UniqueIdentifier/UniqueIdentifier.h @@ -1,5 +1,5 @@ // -// PGUniqueIdentifier.h +// UniqueIdentifier.h // UniqueIdentifierPlugin // // Created by Andrew Thorp on 4/13/12 @@ -18,9 +18,14 @@ // #import -#import -@interface PGUniqueIdentifier : PGPlugin { +#ifdef CORDOVA_FRAMEWORK +#import +#else +#import "CORDOVA/CDVPlugin.h" +#endif + +@interface UniqueIdentifier : CDVPlugin { NSString* callbackId; NSString* uuidString; CFUUIDRef uuid; @@ -32,4 +37,4 @@ - (void) generateUUID:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options; - (void) getUUID:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options; -@end \ No newline at end of file +@end diff --git a/iOS/UniqueIdentifier/UniqueIdentifier.js b/iOS/UniqueIdentifier/UniqueIdentifier.js index 8854214..42dcee0 100644 --- a/iOS/UniqueIdentifier/UniqueIdentifier.js +++ b/iOS/UniqueIdentifier/UniqueIdentifier.js @@ -1,11 +1,44 @@ -var PGUniqueIdentifier = { +// +// UniqueIdentifier.js +// UniqueIdentifierPlugin +// +// Created by Andrew Thorp on 4/13/12 +// +// +// THIS SOFTWARE IS PROVIDED BY THE ANDREW THORP "AS IS" AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +// EVENT SHALL ANDREW TRICE OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// - generateUUID: function(success, fail) { - return PhoneGap.exec(success, fail, "PGUniqueIdentifier", "generateUUID", []); - }, +var UniqueIdentifier = function(){ - getUUID: function(success, fail) { - return PhoneGap.exec(success, fail, "PGUniqueIdentifier", "getUUID", []); - } - -}; \ No newline at end of file +} + +/** + * Generate new UUID + */ +UniqueIdentifier.prototype.generateUUID = function(success, fail){ + Cordova.exec(success, fail, "UniqueIdentifier", "generateUUID", []); +}; + +/** + * Return UUID stored in NSDefaults + */ +UniqueIdentifier.prototype.getUUID = function(success, fail){ + Cordova.exec(success, fail, "UniqueIdentifier", "getUUID", []); +}; + +Cordova.addConstructor(function(){ + if (!window.plugins){ + window.plugins = {}; + } + + window.plugins.uniqueIdentifier = new UniqueIdentifier(); +}); diff --git a/iOS/UniqueIdentifier/PGUniqueIdentifier.m b/iOS/UniqueIdentifier/UniqueIdentifier.m similarity index 80% rename from iOS/UniqueIdentifier/PGUniqueIdentifier.m rename to iOS/UniqueIdentifier/UniqueIdentifier.m index 3285c5e..ac9d219 100644 --- a/iOS/UniqueIdentifier/PGUniqueIdentifier.m +++ b/iOS/UniqueIdentifier/UniqueIdentifier.m @@ -1,5 +1,5 @@ // -// PGUniqueIdentifier.m +// UniqueIdentifier.m // UniqueIdentifierPlugin // // Created by Andrew Thorp on 4/13/12 @@ -17,10 +17,10 @@ // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // -#import "PGUniqueIdentifier.h" +#import "UniqueIdentifier.h" #define UUID_USER_DEFAULTS_KEY @"UUID" -@implementation PGUniqueIdentifier +@implementation UniqueIdentifier @synthesize callbackID; @@ -40,28 +40,28 @@ NSString* UNIQUE_IDENTIFIER_ERROR = @"ERROR"; if ([defaults stringForKey:UUID_USER_DEFAULTS_KEY] == nil) { [defaults setObject:uuidString forKey:UUID_USER_DEFAULTS_KEY]; [defaults synchronize]; - } + } NSString *uniqueIdentifier = [defaults stringForKey:UUID_USER_DEFAULTS_KEY]; - - PluginResult* pluginResult = [PluginResult resultWithStatus:PGCommandStatus_OK messageAsString: uniqueIdentifier]; + + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: uniqueIdentifier]; [self writeJavascript: [pluginResult toSuccessCallbackString:self.callbackID]]; } - (void) getUUID:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options { self.callbackID = [arguments pop]; - PluginResult* pluginResult; + CDVPluginResult* pluginResult; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; if ([defaults stringForKey:UUID_USER_DEFAULTS_KEY] == nil){ - pluginResult = [PluginResult resultWithStatus:PGCommandStatus_ERROR messageAsString: UNIQUE_IDENTIFIER_ERROR]; - [self writeJavascript: [pluginResult toErrorCallbackString:self.callbackID]]; + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString: UNIQUE_IDENTIFIER_ERROR]; + [self writeJavascript: [pluginResult toErrorCallbackString:self.callbackID]]; } else { NSString *uniqueIdentifier = [defaults stringForKey:UUID_USER_DEFAULTS_KEY]; - pluginResult = [PluginResult resultWithStatus:PGCommandStatus_OK messageAsString: uniqueIdentifier]; + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: uniqueIdentifier]; [self writeJavascript: [pluginResult toSuccessCallbackString:self.callbackID]]; } } -@end \ No newline at end of file +@end From a39642bdaf388496599324e7eb8c96f1d367d0c3 Mon Sep 17 00:00:00 2001 From: Andrew Thorp Date: Tue, 8 May 2012 11:59:47 -0400 Subject: [PATCH 5/6] moved iPhone version to correct folder also updated generateUUID logic to not call unnecessary logic --- .../PGUniqueIdentifier.h | 0 .../PGUniqueIdentifier.m | 20 +++++++++---------- .../{UniqueIdentifier => }/README.md | 0 .../UniqueIdentifier.js | 0 4 files changed, 10 insertions(+), 10 deletions(-) rename iPhone/UniqueIdentifier/{UniqueIdentifier => }/PGUniqueIdentifier.h (100%) rename iPhone/UniqueIdentifier/{UniqueIdentifier => }/PGUniqueIdentifier.m (91%) rename iPhone/UniqueIdentifier/{UniqueIdentifier => }/README.md (100%) rename iPhone/UniqueIdentifier/{UniqueIdentifier => }/UniqueIdentifier.js (100%) diff --git a/iPhone/UniqueIdentifier/UniqueIdentifier/PGUniqueIdentifier.h b/iPhone/UniqueIdentifier/PGUniqueIdentifier.h similarity index 100% rename from iPhone/UniqueIdentifier/UniqueIdentifier/PGUniqueIdentifier.h rename to iPhone/UniqueIdentifier/PGUniqueIdentifier.h diff --git a/iPhone/UniqueIdentifier/UniqueIdentifier/PGUniqueIdentifier.m b/iPhone/UniqueIdentifier/PGUniqueIdentifier.m similarity index 91% rename from iPhone/UniqueIdentifier/UniqueIdentifier/PGUniqueIdentifier.m rename to iPhone/UniqueIdentifier/PGUniqueIdentifier.m index 3285c5e..075895b 100644 --- a/iPhone/UniqueIdentifier/UniqueIdentifier/PGUniqueIdentifier.m +++ b/iPhone/UniqueIdentifier/PGUniqueIdentifier.m @@ -30,20 +30,20 @@ NSString* UNIQUE_IDENTIFIER_ERROR = @"ERROR"; - (void) generateUUID:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options { self.callbackID = [arguments pop]; - uuid = CFUUIDCreate(NULL); - if (uuid) { - uuidString = (NSString *)CFUUIDCreateString(NULL, uuid); - CFRelease(uuid); - } NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; if ([defaults stringForKey:UUID_USER_DEFAULTS_KEY] == nil) { + uuid = CFUUIDCreate(NULL); + if (uuid) { + uuidString = (NSString *)CFUUIDCreateString(NULL, uuid); + CFRelease(uuid); + } [defaults setObject:uuidString forKey:UUID_USER_DEFAULTS_KEY]; [defaults synchronize]; - } + } NSString *uniqueIdentifier = [defaults stringForKey:UUID_USER_DEFAULTS_KEY]; - + PluginResult* pluginResult = [PluginResult resultWithStatus:PGCommandStatus_OK messageAsString: uniqueIdentifier]; [self writeJavascript: [pluginResult toSuccessCallbackString:self.callbackID]]; } @@ -55,8 +55,8 @@ NSString* UNIQUE_IDENTIFIER_ERROR = @"ERROR"; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; if ([defaults stringForKey:UUID_USER_DEFAULTS_KEY] == nil){ - pluginResult = [PluginResult resultWithStatus:PGCommandStatus_ERROR messageAsString: UNIQUE_IDENTIFIER_ERROR]; - [self writeJavascript: [pluginResult toErrorCallbackString:self.callbackID]]; + pluginResult = [PluginResult resultWithStatus:PGCommandStatus_ERROR messageAsString: UNIQUE_IDENTIFIER_ERROR]; + [self writeJavascript: [pluginResult toErrorCallbackString:self.callbackID]]; } else { NSString *uniqueIdentifier = [defaults stringForKey:UUID_USER_DEFAULTS_KEY]; pluginResult = [PluginResult resultWithStatus:PGCommandStatus_OK messageAsString: uniqueIdentifier]; @@ -64,4 +64,4 @@ NSString* UNIQUE_IDENTIFIER_ERROR = @"ERROR"; } } -@end \ No newline at end of file +@end diff --git a/iPhone/UniqueIdentifier/UniqueIdentifier/README.md b/iPhone/UniqueIdentifier/README.md similarity index 100% rename from iPhone/UniqueIdentifier/UniqueIdentifier/README.md rename to iPhone/UniqueIdentifier/README.md diff --git a/iPhone/UniqueIdentifier/UniqueIdentifier/UniqueIdentifier.js b/iPhone/UniqueIdentifier/UniqueIdentifier.js similarity index 100% rename from iPhone/UniqueIdentifier/UniqueIdentifier/UniqueIdentifier.js rename to iPhone/UniqueIdentifier/UniqueIdentifier.js From 2f7d11727b46c89250beb08c956cba2ac3d4cc08 Mon Sep 17 00:00:00 2001 From: Andrew Thorp Date: Tue, 8 May 2012 11:59:58 -0400 Subject: [PATCH 6/6] updated generateUUID to not call unneeded logic --- iOS/UniqueIdentifier/UniqueIdentifier.m | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/iOS/UniqueIdentifier/UniqueIdentifier.m b/iOS/UniqueIdentifier/UniqueIdentifier.m index ac9d219..3b50548 100644 --- a/iOS/UniqueIdentifier/UniqueIdentifier.m +++ b/iOS/UniqueIdentifier/UniqueIdentifier.m @@ -30,16 +30,17 @@ NSString* UNIQUE_IDENTIFIER_ERROR = @"ERROR"; - (void) generateUUID:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options { self.callbackID = [arguments pop]; - uuid = CFUUIDCreate(NULL); - if (uuid) { - uuidString = (NSString *)CFUUIDCreateString(NULL, uuid); - CFRelease(uuid); - } NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; if ([defaults stringForKey:UUID_USER_DEFAULTS_KEY] == nil) { - [defaults setObject:uuidString forKey:UUID_USER_DEFAULTS_KEY]; - [defaults synchronize]; + uuid = CFUUIDCreate(NULL); + if (uuid) { + uuidString = (NSString *)CFUUIDCreateString(NULL, uuid); + CFRelease(uuid); + } + + [defaults setObject:uuidString forKey:UUID_USER_DEFAULTS_KEY]; + [defaults synchronize]; } NSString *uniqueIdentifier = [defaults stringForKey:UUID_USER_DEFAULTS_KEY];