Permalink
Browse files

Added option for overriding default locations route and update interv…

…al on the command line
  • Loading branch information...
1 parent 9c1261a commit fab45421e19bd4eaf16bdfb3f918ea8bc06934bb @InfiniteLoopDK InfiniteLoopDK committed with Jan 18, 2011
Showing with 13 additions and 5 deletions.
  1. +1 −0 FTLocationSimulator/FTLocationSimulator.h
  2. +12 −5 FTLocationSimulator/FTLocationSimulator.m
@@ -30,6 +30,7 @@
NSArray *fakeLocations;
CLLocation *location;
NSInteger index;
+ NSTimeInterval updateInterval;
}
@property (nonatomic, retain) CLLocation *location;
@@ -37,16 +37,23 @@ - (void)dealloc
- (void)fakeNewLocation {
// read and parse the KML file
if (!fakeLocations) {
- NSString *fakeLocationsFile = [[NSString alloc] initWithContentsOfFile:[[NSBundle mainBundle]
- pathForResource:@"fakeLocations"
- ofType:@"kml"]];
+ NSString *fakeLocationsPath = [[NSUserDefaults standardUserDefaults] stringForKey:@"FakeLocationsRoute"];
+ if(!fakeLocationsPath)
+ fakeLocationsPath = [[NSBundle mainBundle] pathForResource:@"fakeLocations" ofType:@"kml"];
+
+ NSString *fakeLocationsFile = [[NSString alloc] initWithContentsOfFile:fakeLocationsPath];
NSString *coordinatesString = [fakeLocationsFile stringByMatching:@"<coordinates>[^-0-9]*(.+?)[^-0-9]*</coordinates>"
options:RKLMultiline|RKLDotAll
inRange:NSMakeRange(0, fakeLocationsFile.length)
capture:1
error:NULL];
fakeLocations = [[coordinatesString componentsSeparatedByString:@" "] retain];
[fakeLocationsFile release];
+
+ if([[NSUserDefaults standardUserDefaults] objectForKey:@"FakeLocationsUpdateInterval"])
+ updateInterval = [[NSUserDefaults standardUserDefaults] doubleForKey:@"FakeLocationsUpdateInterval"];
+ else
+ updateInterval = FAKE_CORE_LOCATION_UPDATE_INTERVAL;
}
// select a new fake location
@@ -70,7 +77,7 @@ - (void)fakeNewLocation {
frame.origin.x -= 10;
frame.origin.y -= 10;
[UIView beginAnimations:@"fakeUserLocation" context:nil];
- [UIView setAnimationDuration:FAKE_CORE_LOCATION_UPDATE_INTERVAL];
+ [UIView setAnimationDuration:updateInterval];
userLocationView.frame = frame;
[UIView commitAnimations];
@@ -91,7 +98,7 @@ - (void)fakeNewLocation {
index = 0;
}
- [self performSelector:@selector(fakeNewLocation) withObject:nil afterDelay:FAKE_CORE_LOCATION_UPDATE_INTERVAL];
+ [self performSelector:@selector(fakeNewLocation) withObject:nil afterDelay:updateInterval];
}
}

1 comment on commit fab4542

@futuretap
Owner

Allows specifying as command line arguments:

-FakeLocationsRoute $SRCROOT/TestDate/MyTestRoute.kml

-FakeLocationsUpdateInterval 0.5

Parsing of the commandline arguments are automatically done by NSUserDefaults.

Please sign in to comment.