Permalink
Browse files

[ios-sdk] Fix bug where place picker cache descriptor was ignoring se…

…archText; fix Scrumptious to call it correctly.

Summary:
Two bugs conspired to make caching inconsistent in Scrumptious. Scrumptious was passing "restaurant" as the search text
for the place picker, but not passing it when creating a cache descriptor for background loading. The cache descriptor itself
was also not properly using the searchText to build its URL. Fixed both of those.

Also fixed Scrumptious to be less strict in the accuracy it wants, and don't fill the cache from intermediate low-accuracy
location updates to avoid unnecessary network traffic.

Test Plan:
- Ran unit tests
- Ran Scrumptious on device, did not notice delay when displaying places as I did without this fix

Revert Plan:

Reviewers: jacl, mmarucheck, gregschechte, ayden

Reviewed By: jacl

CC: msdkexp@

Differential Revision: https://phabricator.fb.com/D540969
  • Loading branch information...
1 parent e59c19d commit cc221391fa4ff3292f1ec637794314c158b4e1e2 @clang13 clang13 committed Aug 6, 2012
Showing with 7 additions and 5 deletions.
  1. +6 −4 samples/Scrumptious/scrumptious/SCViewController.m
  2. +1 −1 src/FBPlacePickerCacheDescriptor.m
View
10 samples/Scrumptious/scrumptious/SCViewController.m
@@ -384,7 +384,7 @@ - (void)viewDidLoad {
// Get the CLLocationManager going.
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
- self.locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
+ self.locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
// We don't want to be notified of small changes in location, preferring to use our
// last cached results, if any.
self.locationManager.distanceFilter = 50;
@@ -637,14 +637,16 @@ - (void)locationManager:(CLLocationManager *)manager
fromLocation:(CLLocation *)oldLocation {
if (!oldLocation ||
(oldLocation.coordinate.latitude != newLocation.coordinate.latitude &&
- oldLocation.coordinate.longitude != newLocation.coordinate.longitude)) {
+ oldLocation.coordinate.longitude != newLocation.coordinate.longitude &&
+ newLocation.horizontalAccuracy <= 100.0)) {
// FBSample logic
// If we already have a place picker, reload its data. If not, pre-fetch the
- // data so it is displayed quickly on first use of the place picker.
+ // data so it is displayed quickly on first use of the place picker. Don't waste
+ // time caching data if we aren't at our desired level of accuracy.
FBCacheDescriptor *cacheDescriptor =
[FBPlacePickerViewController cacheDescriptorWithLocationCoordinate:newLocation.coordinate
radiusInMeters:1000
- searchText:nil
+ searchText:@"restaurant"
resultsLimit:50
fieldsForRequest:nil];
[cacheDescriptor prefetchAndCacheForSession:FBSession.activeSession];
View
2 src/FBPlacePickerCacheDescriptor.m
@@ -53,6 +53,7 @@ - (id)initWithLocationCoordinate:(CLLocationCoordinate2D)locationCoordinate
if (self) {
self.locationCoordinate = locationCoordinate;
self.radiusInMeters = radiusInMeters <= 0 ? defaultRadius : radiusInMeters;
+ self.searchText = searchText;
self.resultsLimit = resultsLimit <= 0 ? defaultResultsLimit : resultsLimit;
self.fieldsForRequest = fieldsForRequest;
self.hasCompletedFetch = NO;
@@ -75,7 +76,6 @@ - (void)prefetchAndCacheForSession:(FBSession*)session {
// datasource has some field ownership, so we need one here
FBGraphObjectTableDataSource *datasource = [[[FBGraphObjectTableDataSource alloc] init] autorelease];
- //datasource.groupByField = @"name";
// create the request object that we will start with
FBRequest *request = [FBPlacePickerViewController requestForPlacesSearchAtCoordinate:self.locationCoordinate

0 comments on commit cc22139

Please sign in to comment.