You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2013/08/16 18:50:52 UTC
[4/5] git commit: [CB-4474] Unbreak globailization plugin on 3.0 for
iOS.
[CB-4474] Unbreak globailization plugin on 3.0 for iOS.
arguments, options => command
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/commit/5ba0900f
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/tree/5ba0900f
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/diff/5ba0900f
Branch: refs/heads/master
Commit: 5ba0900fb35a26cdb3f3df3f7d8237fd752ac923
Parents: 8f00875
Author: apla <do...@gmail.com>
Authored: Sun Aug 4 14:48:03 2013 +0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Fri Aug 16 12:39:33 2013 -0400
----------------------------------------------------------------------
src/ios/CDVGlobalization.h | 24 +++---
src/ios/CDVGlobalization.m | 159 +++++++++++++++++++++++++++++++---------
2 files changed, 135 insertions(+), 48 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/blob/5ba0900f/src/ios/CDVGlobalization.h
----------------------------------------------------------------------
diff --git a/src/ios/CDVGlobalization.h b/src/ios/CDVGlobalization.h
index 45ab335..379b704 100644
--- a/src/ios/CDVGlobalization.h
+++ b/src/ios/CDVGlobalization.h
@@ -39,7 +39,7 @@ typedef NSUInteger CDVGlobalizationError;
CFLocaleRef currentLocale;
}
-- (void)getPreferredLanguage:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+- (void)getPreferredLanguage:(CDVInvokedUrlCommand*)command;
/**
* Returns the string identifier for the clients current locale setting.
@@ -47,7 +47,7 @@ typedef NSUInteger CDVGlobalizationError;
* properties object as a parameter. If there is an error getting the locale,
* then the errorCB callback is invoked.
*/
-- (void)getLocaleName:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+- (void)getLocaleName:(CDVInvokedUrlCommand*)command;
/**
* Returns a date formatted as a string according to the clients user preferences and
@@ -57,7 +57,7 @@ typedef NSUInteger CDVGlobalizationError;
*
* options: "date" contains the number of milliseconds that represents the JavaScript date
*/
-- (void)dateToString:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+- (void)dateToString:(CDVInvokedUrlCommand*)command;
/**
* Parses a date formatted as a string according to the clients user
@@ -68,7 +68,7 @@ typedef NSUInteger CDVGlobalizationError;
*
* options: "dateString" contains the JavaScript string to parse for a date
*/
-- (void)stringToDate:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+- (void)stringToDate:(CDVInvokedUrlCommand*)command;
/**
* Returns a pattern string for formatting and parsing dates according to the clients
@@ -77,7 +77,7 @@ typedef NSUInteger CDVGlobalizationError;
* then the errorCB callback is invoked.
*
*/
-- (void)getDatePattern:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+- (void)getDatePattern:(CDVInvokedUrlCommand*)command;
/**
* Returns an array of either the names of the months or days of the week
@@ -86,7 +86,7 @@ typedef NSUInteger CDVGlobalizationError;
* names, then the errorCB callback is invoked.
*
*/
-- (void)getDateNames:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+- (void)getDateNames:(CDVInvokedUrlCommand*)command;
/**
* Returns whether daylight savings time is in effect for a given date using the clients
@@ -97,7 +97,7 @@ typedef NSUInteger CDVGlobalizationError;
* options: "date" contains the number of milliseconds that represents the JavaScript date
*
*/
-- (void)isDayLightSavingsTime:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+- (void)isDayLightSavingsTime:(CDVInvokedUrlCommand*)command;
/**
* Returns the first day of the week according to the clients user preferences and calendar.
@@ -106,7 +106,7 @@ typedef NSUInteger CDVGlobalizationError;
* If there is an error obtaining the pattern, then the errorCB callback is invoked.
*
*/
-- (void)getFirstDayOfWeek:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+- (void)getFirstDayOfWeek:(CDVInvokedUrlCommand*)command;
/**
* Returns a number formatted as a string according to the clients user preferences.
@@ -116,7 +116,7 @@ typedef NSUInteger CDVGlobalizationError;
* options: "number" contains the JavaScript number to format
*
*/
-- (void)numberToString:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+- (void)numberToString:(CDVInvokedUrlCommand*)command;
/**
* Parses a number formatted as a string according to the clients user preferences and
@@ -127,7 +127,7 @@ typedef NSUInteger CDVGlobalizationError;
* options: "numberString" contains the JavaScript string to parse for a number
*
*/
-- (void)stringToNumber:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+- (void)stringToNumber:(CDVInvokedUrlCommand*)command;
/**
* Returns a pattern string for formatting and parsing numbers according to the clients user
@@ -135,7 +135,7 @@ typedef NSUInteger CDVGlobalizationError;
* parameter. If there is an error obtaining the pattern, then the errorCB callback is invoked.
*
*/
-- (void)getNumberPattern:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+- (void)getNumberPattern:(CDVInvokedUrlCommand*)command;
/**
* Returns a pattern string for formatting and parsing currency values according to the clients
@@ -145,6 +145,6 @@ typedef NSUInteger CDVGlobalizationError;
*
* options: "currencyCode" contains the ISO currency code from JavaScript
*/
-- (void)getCurrencyPattern:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+- (void)getCurrencyPattern:(CDVInvokedUrlCommand*)command;
@end
http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/blob/5ba0900f/src/ios/CDVGlobalization.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVGlobalization.m b/src/ios/CDVGlobalization.m
index 9eb9721..abeb529 100644
--- a/src/ios/CDVGlobalization.m
+++ b/src/ios/CDVGlobalization.m
@@ -30,9 +30,8 @@
return self;
}
-- (void)getPreferredLanguage:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void)getPreferredLanguage:(CDVInvokedUrlCommand*)command
{
- NSString* callbackId = [arguments objectAtIndex:0];
CDVPluginResult* result = nil;
NSLog(@"log1");
@@ -53,13 +52,12 @@
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
}
- [self.commandDelegate sendPluginResult:result callbackId:callbackId];
+ [self.commandDelegate sendPluginResult:result callbackId:[command callbackId]];
}
-- (void)getLocaleName:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void)getLocaleName:(CDVInvokedUrlCommand*)command
{
CDVPluginResult* result = nil;
- NSString* callbackId = [arguments objectAtIndex:0];
NSDictionary* dictionary = nil;
NSLocale* locale = [NSLocale currentLocale];
@@ -75,10 +73,10 @@
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
}
- [self.commandDelegate sendPluginResult:result callbackId:callbackId];
+ [self.commandDelegate sendPluginResult:result callbackId:[command callbackId]];
}
-- (void)dateToString:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void)dateToString:(CDVInvokedUrlCommand*)command
{
CFDateFormatterStyle style = kCFDateFormatterShortStyle;
CFDateFormatterStyle dateStyle = kCFDateFormatterShortStyle;
@@ -86,7 +84,17 @@
NSDate* date = nil;
NSString* dateString = nil;
CDVPluginResult* result = nil;
- NSString* callBackId = [arguments objectAtIndex:0];
+
+ NSDictionary* options;
+
+ if ([command.arguments count] > 0) {
+ options = [command.arguments objectAtIndex:0];
+ }
+ if (!options) {
+ result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"no options given"];
+ [self.commandDelegate sendPluginResult:result callbackId:[command callbackId]];
+ return;
+ }
id milliseconds = [options valueForKey:@"date"];
@@ -162,21 +170,31 @@
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
}
- [self.commandDelegate sendPluginResult:result callbackId:callBackId];
+ [self.commandDelegate sendPluginResult:result callbackId:[command callbackId]];
CFRelease(formatter);
}
-- (void)stringToDate:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void)stringToDate:(CDVInvokedUrlCommand*)command
{
CFDateFormatterStyle style = kCFDateFormatterShortStyle;
CFDateFormatterStyle dateStyle = kCFDateFormatterShortStyle;
CFDateFormatterStyle timeStyle = kCFDateFormatterShortStyle;
CDVPluginResult* result = nil;
- NSString* callBackId = [arguments objectAtIndex:0];
NSString* dateString = nil;
NSDateComponents* comps = nil;
+ NSDictionary* options;
+
+ if ([command.arguments count] > 0) {
+ options = [command.arguments objectAtIndex:0];
+ }
+ if (!options) {
+ result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"no options given"];
+ [self.commandDelegate sendPluginResult:result callbackId:[command callbackId]];
+ return;
+ }
+
// get the string that is to be parsed for a date
id ms = [options valueForKey:@"dateString"];
@@ -279,18 +297,28 @@
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
}
- [self.commandDelegate sendPluginResult:result callbackId:callBackId];
+ [self.commandDelegate sendPluginResult:result callbackId:[command callbackId]];
CFRelease(formatter);
}
-- (void)getDatePattern:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void)getDatePattern:(CDVInvokedUrlCommand*)command
{
CFDateFormatterStyle style = kCFDateFormatterShortStyle;
CFDateFormatterStyle dateStyle = kCFDateFormatterShortStyle;
CFDateFormatterStyle timeStyle = kCFDateFormatterShortStyle;
CDVPluginResult* result = nil;
- NSString* callBackId = [arguments objectAtIndex:0];
+
+ NSDictionary* options;
+
+ if ([command.arguments count] > 0) {
+ options = [command.arguments objectAtIndex:0];
+ }
+ if (!options) {
+ result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"no options given"];
+ [self.commandDelegate sendPluginResult:result callbackId:[command callbackId]];
+ return;
+ }
// see if any options have been specified
id items = [options valueForKey:@"options"];
@@ -365,7 +393,7 @@
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
}
- [self.commandDelegate sendPluginResult:result callbackId:callBackId];
+ [self.commandDelegate sendPluginResult:result callbackId:[command callbackId]];
if (timezone) {
CFRelease(timezone);
@@ -373,13 +401,23 @@
CFRelease(formatter);
}
-- (void)getDateNames:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void)getDateNames:(CDVInvokedUrlCommand*)command
{
int style = CDV_FORMAT_LONG;
int selector = CDV_SELECTOR_MONTHS;
CFStringRef dataStyle = kCFDateFormatterMonthSymbols;
CDVPluginResult* result = nil;
- NSString* callBackId = [arguments objectAtIndex:0];
+
+ NSDictionary* options;
+
+ if ([command.arguments count] > 0) {
+ options = [command.arguments objectAtIndex:0];
+ }
+ if (!options) {
+ result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"no options given"];
+ [self.commandDelegate sendPluginResult:result callbackId:[command callbackId]];
+ return;
+ }
// see if any options have been specified
id items = [options valueForKey:@"options"];
@@ -444,16 +482,26 @@
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
}
- [self.commandDelegate sendPluginResult:result callbackId:callBackId];
+ [self.commandDelegate sendPluginResult:result callbackId:[command callbackId]];
CFRelease(formatter);
}
-- (void)isDayLightSavingsTime:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void)isDayLightSavingsTime:(CDVInvokedUrlCommand*)command
{
NSDate* date = nil;
CDVPluginResult* result = nil;
- NSString* callBackId = [arguments objectAtIndex:0];
+
+ NSDictionary* options;
+
+ if ([command.arguments count] > 0) {
+ options = [command.arguments objectAtIndex:0];
+ }
+ if (!options) {
+ result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"no options given"];
+ [self.commandDelegate sendPluginResult:result callbackId:[command callbackId]];
+ return;
+ }
id milliseconds = [options valueForKey:@"date"];
@@ -478,13 +526,12 @@
[dictionary setValue:@"Unknown error" forKey:@"message"];
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
}
- [self.commandDelegate sendPluginResult:result callbackId:callBackId];
+ [self.commandDelegate sendPluginResult:result callbackId:[command callbackId]];
}
-- (void)getFirstDayOfWeek:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void)getFirstDayOfWeek:(CDVInvokedUrlCommand*)command
{
CDVPluginResult* result = nil;
- NSString* callBackId = [arguments objectAtIndex:0];
NSCalendar* calendar = [NSCalendar autoupdatingCurrentCalendar];
@@ -502,16 +549,26 @@
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
}
- [self.commandDelegate sendPluginResult:result callbackId:callBackId];
+ [self.commandDelegate sendPluginResult:result callbackId:[command callbackId]];
}
-- (void)numberToString:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void)numberToString:(CDVInvokedUrlCommand*)command
{
CDVPluginResult* result = nil;
- NSString* callBackId = [arguments objectAtIndex:0];
CFNumberFormatterStyle style = kCFNumberFormatterDecimalStyle;
NSNumber* number = nil;
+ NSDictionary* options;
+
+ if ([command.arguments count] > 0) {
+ options = [command.arguments objectAtIndex:0];
+ }
+ if (!options) {
+ result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"no options given"];
+ [self.commandDelegate sendPluginResult:result callbackId:[command callbackId]];
+ return;
+ }
+
id value = [options valueForKey:@"number"];
if (value && [value isKindOfClass:[NSNumber class]]) {
@@ -566,19 +623,29 @@
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
}
- [self.commandDelegate sendPluginResult:result callbackId:callBackId];
+ [self.commandDelegate sendPluginResult:result callbackId:[command callbackId]];
CFRelease(formatter);
}
-- (void)stringToNumber:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void)stringToNumber:(CDVInvokedUrlCommand*)command
{
CDVPluginResult* result = nil;
- NSString* callBackId = [arguments objectAtIndex:0];
CFNumberFormatterStyle style = kCFNumberFormatterDecimalStyle;
NSString* numberString = nil;
double doubleValue;
+ NSDictionary* options;
+
+ if ([command.arguments count] > 0) {
+ options = [command.arguments objectAtIndex:0];
+ }
+ if (!options) {
+ result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"no options given"];
+ [self.commandDelegate sendPluginResult:result callbackId:[command callbackId]];
+ return;
+ }
+
id value = [options valueForKey:@"numberString"];
if (value && [value isKindOfClass:[NSString class]]) {
@@ -640,19 +707,29 @@
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
}
- [self.commandDelegate sendPluginResult:result callbackId:callBackId];
+ [self.commandDelegate sendPluginResult:result callbackId:[command callbackId]];
CFRelease(formatter);
}
-- (void)getNumberPattern:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void)getNumberPattern:(CDVInvokedUrlCommand*)command
{
CDVPluginResult* result = nil;
- NSString* callBackId = [arguments objectAtIndex:0];
CFNumberFormatterStyle style = kCFNumberFormatterDecimalStyle;
CFStringRef symbolType = NULL;
NSString* symbol = @"";
+ NSDictionary* options;
+
+ if ([command.arguments count] > 0) {
+ options = [command.arguments objectAtIndex:0];
+ }
+ if (!options) {
+ result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"no options given"];
+ [self.commandDelegate sendPluginResult:result callbackId:[command callbackId]];
+ return;
+ }
+
// see if any options have been specified
id items = [options valueForKey:@"options"];
@@ -720,15 +797,14 @@
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
}
- [self.commandDelegate sendPluginResult:result callbackId:callBackId];
+ [self.commandDelegate sendPluginResult:result callbackId:[command callbackId]];
CFRelease(formatter);
}
-- (void)getCurrencyPattern:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+- (void)getCurrencyPattern:(CDVInvokedUrlCommand*)command
{
CDVPluginResult* result = nil;
- NSString* callBackId = [arguments objectAtIndex:0];
NSString* currencyCode = nil;
NSString* numberPattern = nil;
NSString* decimal = nil;
@@ -737,6 +813,17 @@
double roundingIncrement;
Boolean rc;
+ NSDictionary* options;
+
+ if ([command.arguments count] > 0) {
+ options = [command.arguments objectAtIndex:0];
+ }
+ if (!options) {
+ result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"no options given"];
+ [self.commandDelegate sendPluginResult:result callbackId:[command callbackId]];
+ return;
+ }
+
id value = [options valueForKey:@"currencyCode"];
if (value && [value isKindOfClass:[NSString class]]) {
@@ -776,7 +863,7 @@
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
}
- [self.commandDelegate sendPluginResult:result callbackId:callBackId];
+ [self.commandDelegate sendPluginResult:result callbackId:[command callbackId]];
}
- (void)dealloc