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/04/04 20:19:04 UTC

ios commit: Fixes cb-361 & use timeout to turn off compass sensor

Updated Branches:
  refs/heads/master 23f12c0e2 -> 7daaf0401


Fixes cb-361 & use timeout to turn off compass sensor

Update for unified JS to remove headingRepeats parameter and
refactored to use timeout to turn off heading sensor (matches current implementation
of Android).
Updated to pass options.filter into getHeading to indicate a watch by Filter request


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/7daaf040
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/7daaf040
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/7daaf040

Branch: refs/heads/master
Commit: 7daaf0401e76a08ddc23e1c70bc65ad57e73678a
Parents: 23f12c0
Author: Becky Gibson <be...@apache.org>
Authored: Tue Apr 3 16:02:32 2012 -0400
Committer: Becky Gibson <be...@apache.org>
Committed: Wed Apr 4 14:18:14 2012 -0400

----------------------------------------------------------------------
 CordovaLib/Classes/CDVLocation.h |   17 +++++++-----
 CordovaLib/Classes/CDVLocation.m |   48 +++++++++++++++++++-------------
 2 files changed, 38 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/7daaf040/CordovaLib/Classes/CDVLocation.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVLocation.h b/CordovaLib/Classes/CDVLocation.h
index ae6b4b9..d004a21 100755
--- a/CordovaLib/Classes/CDVLocation.h
+++ b/CordovaLib/Classes/CDVLocation.h
@@ -39,19 +39,21 @@ typedef NSUInteger CDVLocationStatus;
 
 // simple object to keep track of heading information
 @interface CDVHeadingData : NSObject {
-    CDVHeadingStatus     headingStatus;
-    BOOL              headingRepeats;
-    CLHeading*        headingInfo;
-    NSMutableArray*   headingCallbacks;
-    NSString*         headingFilter;
+    CDVHeadingStatus    headingStatus;
+    CLHeading*          headingInfo;
+    NSMutableArray*     headingCallbacks;
+    NSString*           headingFilter;
+    NSDate*             headingTimestamp;
+    NSInteger           timeout;
     
 }
 
 @property (nonatomic, assign) CDVHeadingStatus headingStatus;
-@property (nonatomic, assign) BOOL headingRepeats;
 @property (nonatomic, retain) CLHeading* headingInfo;
 @property (nonatomic, retain) NSMutableArray* headingCallbacks;
 @property (nonatomic, retain) NSString* headingFilter;
+@property (nonatomic, retain) NSDate* headingTimestamp;
+@property (assign) NSInteger timeout;
 
 @end
 
@@ -70,6 +72,7 @@ typedef NSUInteger CDVLocationStatus;
 
 @interface CDVLocation : CDVPlugin <CLLocationManagerDelegate> {
     @private BOOL      __locationStarted;
+    CLLocationManager* locationManager;
     CDVHeadingData*    headingData;
     CDVLocationData*   locationData;
 }
@@ -97,7 +100,7 @@ typedef NSUInteger CDVLocationStatus;
 
 - (void)getHeading:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
 - (void)returnHeadingInfo: (NSString*) callbackId keepCallback: (BOOL) bRetain;
-
+- (void)watchHeadingFilter:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
 - (void)stopHeading:(NSMutableArray*)arguments
 		   withDict:(NSMutableDictionary*)options;
 - (void) startHeadingWithFilter: (CLLocationDegrees) filter;

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/7daaf040/CordovaLib/Classes/CDVLocation.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVLocation.m b/CordovaLib/Classes/CDVLocation.m
index 5129146..269fb2c 100755
--- a/CordovaLib/Classes/CDVLocation.m
+++ b/CordovaLib/Classes/CDVLocation.m
@@ -56,17 +56,18 @@
 
 @implementation CDVHeadingData
 
-@synthesize headingStatus, headingRepeats, headingInfo, headingCallbacks, headingFilter;
+@synthesize headingStatus, headingInfo, headingCallbacks, headingFilter, headingTimestamp, timeout;
 -(CDVHeadingData*) init
 {
     self = (CDVHeadingData*)[super init];
     if (self) 
 	{
-        self.headingRepeats = NO;
         self.headingStatus = HEADINGSTOPPED;
         self.headingInfo = nil;
         self.headingCallbacks = nil;
         self.headingFilter = nil;
+        self.headingTimestamp = nil;
+        self.timeout = 10;
     }
     return self;
 }
@@ -75,6 +76,7 @@
     self.headingInfo = nil;
     self.headingCallbacks = nil;
     self.headingFilter = nil;
+    self.headingTimestamp = nil;
     [super dealloc];  
 }
 
@@ -350,8 +352,11 @@
 - (void)getHeading:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
 {
     NSString* callbackId = [arguments objectAtIndex:0];
-    NSNumber* repeats = [options valueForKey:@"repeats"];  // indicates this call will be repeated at regular intervals
-    
+    NSNumber* filter = [options valueForKey:@"filter"];
+    if (filter) {
+        [self watchHeadingFilter: arguments withDict: options];
+        return;
+    }
     if ([self hasHeadingSupport] == NO) 
     {
         CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt:20];
@@ -359,13 +364,10 @@
     } else {
         // heading retrieval does is not affected by disabling locationServices and authorization of app for location services
         if (!self.headingData) {
-            self.headingData = [[[CDVHeadingData alloc] init] autorelease];
+            self.headingData = [[CDVHeadingData alloc] init];
         }
         CDVHeadingData* hData = self.headingData;
-        
-        if (repeats != nil) {
-            hData.headingRepeats = YES;
-        }
+
         if (!hData.headingCallbacks) {
             hData.headingCallbacks = [NSMutableArray arrayWithCapacity:1];
         }
@@ -394,7 +396,7 @@
         [super writeJavascript:[result toErrorCallbackString:callbackId]];
     } else {
         if (!hData) {
-            self.headingData = [[[CDVHeadingData alloc] init] autorelease];
+            self.headingData = [[CDVHeadingData alloc] init] ;
             hData = self.headingData;
         }
         if (hData.headingStatus != HEADINGRUNNING) {
@@ -421,6 +423,8 @@
     NSString* jsString = nil;
     CDVHeadingData* hData = self.headingData;
     
+    self.headingData.headingTimestamp = [NSDate date];
+    
     if (hData && hData.headingStatus == HEADINGERROR) {
         // return error
         result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt:0];
@@ -450,15 +454,16 @@
 
 - (void) stopHeading:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
 {
-    CDVHeadingData* hData = self.headingData;
-    if (hData && hData.headingStatus != HEADINGSTOPPED)
+    //CDVHeadingData* hData = self.headingData;
+    if (self.headingData && self.headingData.headingStatus != HEADINGSTOPPED)
 	{
-		if (hData.headingFilter) {
+		if (self.headingData.headingFilter) {
             // callback one last time to clear callback
-            [self returnHeadingInfo:hData.headingFilter keepCallback:NO];
-            hData.headingFilter = nil;
+            [self returnHeadingInfo: self.headingData.headingFilter keepCallback:NO];
+            self.headingData.headingFilter = nil;
         }
-        [self.locationManager stopUpdatingHeading];		
+        [self.locationManager stopUpdatingHeading];	
+        NSLog(@"heading STOPPED");
         self.headingData = nil;
 	}
 }	
@@ -495,6 +500,10 @@
     CDVHeadingData* hData = self.headingData;
     // save the data for next call into getHeadingData
     hData.headingInfo = heading;
+    BOOL bTimeout = NO;
+    if (!hData.headingFilter && hData.headingTimestamp) {
+        bTimeout = fabs([hData.headingTimestamp timeIntervalSinceNow ]) > hData.timeout;
+    }
     
     if (hData.headingStatus == HEADINGSTARTING) {
         hData.headingStatus = HEADINGRUNNING; // so returnHeading info will work
@@ -503,12 +512,11 @@
             [self returnHeadingInfo:callbackId keepCallback:NO];
         }
         [hData.headingCallbacks removeAllObjects];
-        if (!hData.headingRepeats && !hData.headingFilter) {
-            [self stopHeading:nil withDict:nil];
-        }
     }
     if (hData.headingFilter) {
         [self returnHeadingInfo: hData.headingFilter keepCallback:YES];
+    } else if (bTimeout) {
+        [self stopHeading:nil withDict:nil];
     }
     hData.headingStatus = HEADINGRUNNING;  // to clear any error
     
@@ -530,7 +538,7 @@
                 }
                 [hData.headingCallbacks removeAllObjects];
             } // else for frequency watches next call to getCurrentHeading will report error
-            else if (hData.headingFilter) {
+            if (hData.headingFilter) {
                 CDVPluginResult* resultFilter = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt:0];
                 [super writeJavascript: [resultFilter toErrorCallbackString:hData.headingFilter]];
             }