You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by mm...@apache.org on 2014/05/05 18:09:08 UTC
[08/49] git commit: CB-5012 ensure result is returned
CB-5012 ensure result is returned
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/commit/e6bb4a84
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/tree/e6bb4a84
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/diff/e6bb4a84
Branch: refs/heads/cdvtest
Commit: e6bb4a844e4a2267dfb8f18a25211893656fa8b6
Parents: 9093259
Author: James Jong <wj...@gmail.com>
Authored: Sat Oct 12 13:21:14 2013 -0400
Committer: James Jong <wj...@gmail.com>
Committed: Sat Oct 12 13:21:14 2013 -0400
----------------------------------------------------------------------
src/ios/CDVAccelerometer.m | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/blob/e6bb4a84/src/ios/CDVAccelerometer.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVAccelerometer.m b/src/ios/CDVAccelerometer.m
index 20bcbc6..e98aacd 100755
--- a/src/ios/CDVAccelerometer.m
+++ b/src/ios/CDVAccelerometer.m
@@ -22,6 +22,7 @@
@interface CDVAccelerometer () {}
@property (readwrite, assign) BOOL isRunning;
+@property (readwrite, assign) BOOL haveReturnedResult;
@property (readwrite, strong) CMMotionManager* motionManager;
@end
@@ -30,7 +31,7 @@
@synthesize callbackId, isRunning;
// defaults to 10 msec
-#define kAccelerometerInterval 40
+#define kAccelerometerInterval 10
// g constant: -9.81 m/s^2
#define kGravitationalConstant -9.81
@@ -44,6 +45,7 @@
timestamp = 0;
self.callbackId = nil;
self.isRunning = NO;
+ self.haveReturnedResult = YES;
self.motionManager = nil;
}
return self;
@@ -56,7 +58,8 @@
- (void)start:(CDVInvokedUrlCommand*)command
{
- NSString* cbId = command.callbackId;
+ self.haveReturnedResult = NO;
+ self.callbackId = command.callbackId;
if (!self.motionManager)
{
@@ -80,7 +83,6 @@
}
}
- self.callbackId = cbId;
}
- (void)onReset
@@ -91,6 +93,10 @@
- (void)stop:(CDVInvokedUrlCommand*)command
{
if ([self.motionManager isAccelerometerAvailable] == YES) {
+ if (self.haveReturnedResult == NO){
+ // block has not fired before stop was called, return whatever result we currently have
+ [self returnAccelInfo];
+ }
[self.motionManager stopAccelerometerUpdates];
}
self.isRunning = NO;
@@ -109,6 +115,7 @@
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:accelProps];
[result setKeepCallback:[NSNumber numberWithBool:YES]];
[self.commandDelegate sendPluginResult:result callbackId:self.callbackId];
+ self.haveReturnedResult = YES;
}
// TODO: Consider using filtering to isolate instantaneous data vs. gravity data -jm