You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by be...@apache.org on 2012/03/21 21:59:06 UTC
ios commit: More Unified JS bug fixes and code cleanup
Updated Branches:
refs/heads/master 701f3cca0 -> 5f2c0b787
More Unified JS bug fixes and code cleanup
*fix warnings in CDVCamera - bad use of || changed to a tertiary statement
*capture - remove references to cast functions and updated to properly find "File" class
*Location - updated returnLocationError to include message
*Updated sound to return MediaError to onStatus when msg is MEDIA_ERROR. Added back support for playing audio multiple times via numberOfLoops option.
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/commit/5f2c0b78
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/5f2c0b78
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/5f2c0b78
Branch: refs/heads/master
Commit: 5f2c0b78730a2a01940b58d7f0669797edc2250b
Parents: 701f3cc
Author: Becky Gibson <be...@apache.org>
Authored: Wed Mar 21 16:47:38 2012 -0400
Committer: Becky Gibson <be...@apache.org>
Committed: Wed Mar 21 16:55:01 2012 -0400
----------------------------------------------------------------------
CordovaLib/Classes/CDVCamera.m | 4 +-
CordovaLib/Classes/CDVCapture.m | 10 ++++----
CordovaLib/Classes/CDVLocation.h | 1 +
CordovaLib/Classes/CDVLocation.m | 32 ++++++++++++++++----------
CordovaLib/Classes/CDVSound.m | 30 +++++++++++-------------
CordovaLib/Classes/CDVViewController.h | 2 +
6 files changed, 44 insertions(+), 35 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/5f2c0b78/CordovaLib/Classes/CDVCamera.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVCamera.m b/CordovaLib/Classes/CDVCamera.m
index 7fa7e60..2d48f0e 100644
--- a/CordovaLib/Classes/CDVCamera.m
+++ b/CordovaLib/Classes/CDVCamera.m
@@ -77,9 +77,9 @@
self.pickerController.correctOrientation = [[options valueForKey:@"correctOrientation"] boolValue];
self.pickerController.saveToPhotoAlbum = [[options valueForKey:@"saveToPhotoAlbum"] boolValue];
- self.pickerController.encodingType = [[arguments objectAtIndex:6] intValue] || EncodingTypeJPEG;
+ self.pickerController.encodingType = ([arguments objectAtIndex:6]) ? [[arguments objectAtIndex:6] intValue] : EncodingTypeJPEG;
- self.pickerController.quality = [[arguments objectAtIndex:1] intValue] || 50;
+ self.pickerController.quality = ([arguments objectAtIndex:1]) ? [[arguments objectAtIndex:1] intValue] : 50;
self.pickerController.returnType = (CDVDestinationType)[[arguments objectAtIndex:2] intValue] || DestinationTypeFileUri;
if (sourceType == UIImagePickerControllerSourceTypeCamera) {
http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/5f2c0b78/CordovaLib/Classes/CDVCapture.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVCapture.m b/CordovaLib/Classes/CDVCapture.m
index bc17462..05d1444 100644
--- a/CordovaLib/Classes/CDVCapture.m
+++ b/CordovaLib/Classes/CDVCapture.m
@@ -199,7 +199,7 @@
NSDictionary* fileDict = [self getMediaDictionaryFromPath:filePath ofType: mimeType];
NSArray* fileArray = [NSArray arrayWithObject:fileDict];
- result = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsArray: fileArray cast:@"navigator.device.capture._castMediaFile"];
+ result = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsArray: fileArray];
jsString = [result toSuccessCallbackString:callbackId];
}
@@ -288,7 +288,7 @@
NSDictionary* fileDict = [self getMediaDictionaryFromPath:moviePath ofType:nil];
NSArray* fileArray = [NSArray arrayWithObject:fileDict];
- result = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsArray: fileArray cast:@"navigator.device.capture._castMediaFile"];
+ result = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsArray: fileArray];
jsString = [result toSuccessCallbackString:callbackId];
//
@@ -361,7 +361,7 @@
if (!mimeType){
// try to determine mime type if not provided
- id command = [self.commandDelegate getCommandInstance: @"org.apache.cordova.file"];
+ id command = [self.commandDelegate getCommandInstance: @"File"];
bError = !([command isKindOfClass:[CDVFile class]]);
if (!bError) {
CDVFile* pgFile = (CDVFile*)command;
@@ -448,7 +448,7 @@
[fileDict setObject: fullPath forKey:@"fullPath"];
// determine type
if(!type) {
- id command = [self.commandDelegate getCommandInstance: @"org.apache.cordova.file"];
+ id command = [self.commandDelegate getCommandInstance: @"File"];
if([command isKindOfClass:[CDVFile class]]) {
CDVFile* pgFile = (CDVFile*)command;
NSString* mimeType = [pgFile getMimeTypeFromPath:fullPath];
@@ -843,7 +843,7 @@
NSDictionary* fileDict = [captureCommand getMediaDictionaryFromPath:filePath ofType: @"audio/wav"];
NSArray* fileArray = [NSArray arrayWithObject:fileDict];
- CDVPluginResult* result = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsArray: fileArray cast:@"navigator.device.capture._castMediaFile"];
+ CDVPluginResult* result = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsArray: fileArray];
self.resultString = [result toSuccessCallbackString:callbackId];
} else {
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageToErrorObject:CAPTURE_INTERNAL_ERR];
http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/5f2c0b78/CordovaLib/Classes/CDVLocation.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVLocation.h b/CordovaLib/Classes/CDVLocation.h
index 6ec0dbc..ae6b4b9 100755
--- a/CordovaLib/Classes/CDVLocation.h
+++ b/CordovaLib/Classes/CDVLocation.h
@@ -82,6 +82,7 @@ typedef NSUInteger CDVLocationStatus;
- (BOOL) hasHeadingSupport;
- (void) getLocation:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
- (void) returnLocationInfo: (NSString*) callbackId;
+- (void) returnLocationError: (NSUInteger) errorCode withMessage: (NSString*) message;
- (void) startLocation;
- (void) stopLocation;
http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/5f2c0b78/CordovaLib/Classes/CDVLocation.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVLocation.m b/CordovaLib/Classes/CDVLocation.m
index d85d7d4..665ea07 100755
--- a/CordovaLib/Classes/CDVLocation.m
+++ b/CordovaLib/Classes/CDVLocation.m
@@ -82,7 +82,7 @@
@implementation CDVLocationData
-@synthesize locationInfo, locationCallbacks;
+@synthesize locationStatus, locationInfo, locationCallbacks;
-(CDVLocationData*) init
{
self = (CDVLocationData*)[super init];
@@ -184,19 +184,25 @@
*/
if (!forcePrompt)
{
- [self returnLocationError:PERMISSIONDENIED];
+ [self returnLocationError:PERMISSIONDENIED withMessage: nil];
return;
}
}
if (![self isAuthorized])
{
- NSUInteger code = -1;
+ NSString* message = nil;
BOOL authStatusAvailable = [CLLocationManager respondsToSelector:@selector(authorizationStatus)]; // iOS 4.2+
if (authStatusAvailable) {
- code = [CLLocationManager authorizationStatus];
+ NSUInteger code = [CLLocationManager authorizationStatus];
+ if (code == kCLAuthorizationStatusNotDetermined) {
+ // could return POSITION_UNAVAILABLE but need to coordinate with other platforms
+ message = @"User undecided on application's use of location services";
+ } else if (code == kCLAuthorizationStatusRestricted) {
+ message = @"application use of location services is restricted";
+ }
}
-
- [self returnLocationError:code];
+ //PERMISSIONDENIED is only PositionError that makes sense when authorization denied
+ [self returnLocationError:PERMISSIONDENIED withMessage: message];
return;
}
@@ -303,7 +309,7 @@
if (lData && !lData.locationInfo) {
// return error
- result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt:POSITIONUNAVAILABLE];
+ result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageToErrorObject:POSITIONUNAVAILABLE];
jsString = [result toErrorCallbackString:callbackId];
} else if (lData && lData.locationInfo) {
CLLocation* lInfo = lData.locationInfo;
@@ -327,10 +333,13 @@
[super writeJavascript:jsString];
}
}
-- (void)returnLocationError: (NSInteger*) errorCode
+- (void)returnLocationError: (NSUInteger) errorCode withMessage: (NSString*) message
{
+ NSMutableDictionary* posError = [NSMutableDictionary dictionaryWithCapacity:2];
+ [posError setObject: [NSNumber numberWithInt: errorCode] forKey:@"code"];
+ [posError setObject: message ? message : @"" forKey: @"message"];
+ CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:posError];
for (NSString *callbackId in self.locationData.locationCallbacks) {
- CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt:*errorCode];
[super writeJavascript:[result toErrorCallbackString:callbackId]];
}
[self.locationData.locationCallbacks removeAllObjects];
@@ -507,7 +516,6 @@
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"locationManager::didFailWithError %@", [error localizedFailureReason]);
- NSString* jsCallback = @"";
// Compass Error
if ([error code] == kCLErrorHeadingFailure)
@@ -538,11 +546,11 @@
// PositionError.PERMISSION_DENIED = 1;
// PositionError.POSITION_UNAVAILABLE = 2;
// PositionError.TIMEOUT = 3;
- NSInteger positionError = POSITIONUNAVAILABLE;
+ NSUInteger positionError = POSITIONUNAVAILABLE;
if (error.code == kCLErrorDenied) {
positionError = PERMISSIONDENIED;
}
- [self returnLocationError:positionError];
+ [self returnLocationError:positionError withMessage: [error localizedDescription]];
}
}
http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/5f2c0b78/CordovaLib/Classes/CDVSound.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVSound.m b/CordovaLib/Classes/CDVSound.m
index 0a5f756..03e9ed4 100644
--- a/CordovaLib/Classes/CDVSound.m
+++ b/CordovaLib/Classes/CDVSound.m
@@ -105,8 +105,8 @@
errMsg = [NSString stringWithFormat: @"Cannot use audio file from resource '%@'", resourcePath];
}
if (bError) {
- jsString = [NSString stringWithFormat: @"%@(\"%@\",%d,%d);", @"cordova.require('cordova/plugin/Media').onStatus", mediaId, MEDIA_ERROR, errcode];
- //jsString = [NSString stringWithFormat: @"%@(\"%@\",%d,%@);", @"require('cordova/plugin/Media').onStatus", mediaId, MEDIA_ERROR,[self createMediaErrorWithCode: errcode message: errMsg]];
+ //jsString = [NSString stringWithFormat: @"%@(\"%@\",%d,%d);", @"cordova.require('cordova/plugin/Media').onStatus", mediaId, MEDIA_ERROR, errcode];
+ jsString = [NSString stringWithFormat: @"%@(\"%@\",%d,%@);", @"cordova.require('cordova/plugin/Media').onStatus", mediaId, MEDIA_ERROR,[self createMediaErrorWithCode: errcode message: errMsg]];
[super writeJavascript:jsString];
} else {
audioFile = [[[CDVAudioFile alloc] init] autorelease];
@@ -179,14 +179,12 @@
}
if (!bError) {
NSLog(@"Playing audio sample '%@'", audioFile.resourcePath);
- /* TODO: do we want to keep numberOfLoops option for iOS only?
NSNumber* loopOption = [options objectForKey:@"numberOfLoops"];
NSInteger numberOfLoops = 0;
if (loopOption != nil) {
numberOfLoops = [loopOption intValue] - 1;
}
audioFile.player.numberOfLoops = numberOfLoops;
- */
if(audioFile.player.isPlaying){
[audioFile.player stop];
audioFile.player.currentTime = 0;
@@ -212,8 +210,8 @@
[audioFile.player play];
} */
// error creating the session or player
- jsString = [NSString stringWithFormat: @"%@(\"%@\",%d,%d);", @"cordova.require('cordova/plugin/Media').onStatus", mediaId, MEDIA_ERROR, MEDIA_ERR_NONE_SUPPORTED];
- //jsString = [NSString stringWithFormat: @"%@(\"%@\",%d,%@);", @"require('cordova/plugin/Media').onStatus", mediaId, MEDIA_ERROR, [self createMediaErrorWithCode: MEDIA_ERR_NONE_SUPPORTED message: nil]];
+ //jsString = [NSString stringWithFormat: @"%@(\"%@\",%d,%d);", @"cordova.require('cordova/plugin/Media').onStatus", mediaId, MEDIA_ERROR, MEDIA_ERR_NONE_SUPPORTED];
+ jsString = [NSString stringWithFormat: @"%@(\"%@\",%d,%@);", @"cordova.require('cordova/plugin/Media').onStatus", mediaId, MEDIA_ERROR, [self createMediaErrorWithCode: MEDIA_ERR_NONE_SUPPORTED message: nil]];
[super writeJavascript:jsString];
}
}
@@ -301,10 +299,10 @@
// NSLog(@"Prepared audio sample '%@' for playback.", audioFile.resourcePath);
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
- jsString = [NSString stringWithFormat: @"%@(\"%@\",%d,%d);\n%@", @"Cordova.Media.onStatus", mediaId, MEDIA_STATE, state, [result toSuccessCallbackString:callbackId]];
+ jsString = [NSString stringWithFormat: @"%@(\"%@\",%d,%d);\n%@", @"cordova.require('cordova/plugin/Media').onStatus", mediaId, MEDIA_STATE, state, [result toSuccessCallbackString:callbackId]];
} else {
- jsString = [NSString stringWithFormat: @"%@(\"%@\",%d,%@);", @"Cordova.Media.onStatus", mediaId, MEDIA_ERROR, [self createMediaErrorWithCode: MEDIA_ERR_NONE_SUPPORTED message: nil]];
+ jsString = [NSString stringWithFormat: @"%@(\"%@\",%d,%@);", @"cordova.require('cordova/plugin/Media').onStatus", mediaId, MEDIA_ERROR, [self createMediaErrorWithCode: MEDIA_ERR_NONE_SUPPORTED message: nil]];
}
if (jsString) {
[super writeJavascript:jsString];
@@ -478,8 +476,8 @@
if (![self.avSession setActive: YES error: &error]){
// other audio with higher priority that does not allow mixing could cause this to fail
errorMsg = [NSString stringWithFormat: @"Unable to record audio: %@", [error localizedFailureReason]];
- jsString = [NSString stringWithFormat: @"%@(\"%@\",%d,%d);", @"cordova.require('cordova/plugin/Media').onStatus", mediaId, MEDIA_ERROR, MEDIA_ERR_ABORTED];
- // jsString = [NSString stringWithFormat: @"%@(\"%@\",%d,%@);", @"require('cordova/plugin/Media').onStatus", mediaId, MEDIA_ERROR, [self createMediaErrorWithCode: MEDIA_ERR_ABORTED message: errorMsg] ];
+ //jsString = [NSString stringWithFormat: @"%@(\"%@\",%d,%d);", @"cordova.require('cordova/plugin/Media').onStatus", mediaId, MEDIA_ERROR, MEDIA_ERR_ABORTED];
+ jsString = [NSString stringWithFormat: @"%@(\"%@\",%d,%@);", @"cordova.require('cordova/plugin/Media').onStatus", mediaId, MEDIA_ERROR, [self createMediaErrorWithCode: MEDIA_ERR_ABORTED message: errorMsg] ];
[super writeJavascript:jsString];
return;
}
@@ -494,8 +492,8 @@
if (self.avSession) {
[self.avSession setActive:NO error:nil];
}
- jsString = [NSString stringWithFormat: @"%@(\"%@\",%d,%d);", @"cordova.require('cordova/plugin/Media').onStatus", mediaId, MEDIA_ERROR, MEDIA_ERR_ABORTED];
- //jsString = [NSString stringWithFormat: @"%@(\"%@\",%d,%@);", @"require('cordova/plugin/Media').onStatus", mediaId, MEDIA_ERROR, [self createMediaErrorWithCode: MEDIA_ERR_ABORTED message: errorMsg]];
+ //jsString = [NSString stringWithFormat: @"%@(\"%@\",%d,%d);", @"cordova.require('cordova/plugin/Media').onStatus", mediaId, MEDIA_ERROR, MEDIA_ERR_ABORTED];
+ jsString = [NSString stringWithFormat: @"%@(\"%@\",%d,%@);", @"cordova.require('cordova/plugin/Media').onStatus", mediaId, MEDIA_ERROR, [self createMediaErrorWithCode: MEDIA_ERR_ABORTED message: errorMsg]];
} else {
audioFile.recorder.delegate = self;
@@ -551,8 +549,8 @@
if (flag){
jsString = [NSString stringWithFormat: @"%@(\"%@\",%d,%d);", @"cordova.require('cordova/plugin/Media').onStatus", mediaId, MEDIA_STATE, MEDIA_STOPPED];
} else {
- jsString = [NSString stringWithFormat: @"%@(\"%@\",%d,%d);", @"cordova.require('cordova/plugin/Media').onStatus", mediaId, MEDIA_ERROR, MEDIA_ERR_DECODE];
- //jsString = [NSString stringWithFormat: @"%@(\"%@\",%d,%@);", @"require('cordova/plugin/Media').onStatus", mediaId, MEDIA_ERROR, [self createMediaErrorWithCode: MEDIA_ERR_DECODE message:nil]];
+ //jsString = [NSString stringWithFormat: @"%@(\"%@\",%d,%d);", @"cordova.require('cordova/plugin/Media').onStatus", mediaId, MEDIA_ERROR, MEDIA_ERR_DECODE];
+ jsString = [NSString stringWithFormat: @"%@(\"%@\",%d,%@);", @"cordova.require('cordova/plugin/Media').onStatuss", mediaId, MEDIA_ERROR, [self createMediaErrorWithCode: MEDIA_ERR_DECODE message:nil]];
}
if (self.avSession) {
[self.avSession setActive:NO error:nil];
@@ -575,8 +573,8 @@
jsString = [NSString stringWithFormat: @"%@(\"%@\",%d,%d);", @"cordova.require('cordova/plugin/Media').onStatus", mediaId, MEDIA_STATE, MEDIA_STOPPED];
} else {
- jsString = [NSString stringWithFormat: @"%@(\"%@\",%d,%d);", @"cordova.require('cordova/plugin/Media').onStatus", mediaId, MEDIA_ERROR, MEDIA_ERR_DECODE];
- //jsString = [NSString stringWithFormat: @"%@(\"%@\",%d,%@);", @"require('cordova/plugin/Media').onStatus", mediaId, MEDIA_ERROR, [self createMediaErrorWithCode: MEDIA_ERR_DECODE message:nil]];
+ //jsString = [NSString stringWithFormat: @"%@(\"%@\",%d,%d);", @"cordova.require('cordova/plugin/Media').onStatus", mediaId, MEDIA_ERROR, MEDIA_ERR_DECODE];
+ jsString = [NSString stringWithFormat: @"%@(\"%@\",%d,%@);", @"cordova.require('cordova/plugin/Media').onStatus", mediaId, MEDIA_ERROR, [self createMediaErrorWithCode: MEDIA_ERR_DECODE message:nil]];
}
if (self.avSession) {
http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/5f2c0b78/CordovaLib/Classes/CDVViewController.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVViewController.h b/CordovaLib/Classes/CDVViewController.h
index 41f4d1b..11a15e1 100644
--- a/CordovaLib/Classes/CDVViewController.h
+++ b/CordovaLib/Classes/CDVViewController.h
@@ -51,12 +51,14 @@
+ (NSString*) cordovaVersion;
+ (NSString*) applicationDocumentsDirectory;
+- (void) printMultitaskingInfo;
- (void) createGapView;
- (int) executeQueuedCommands;
- (void) flushCommandQueue;
- (void) javascriptAlert:(NSString*)text;
+//- (NSString*) pathForResource:(NSString*)resourcepath;
- (NSString*) appURLScheme;
- (NSDictionary*) deviceProperties;