Skip to content

Commit

Permalink
[ios-sdk] Fix bug where place picker cache descriptor was ignoring se…
Browse files Browse the repository at this point in the history
…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
Chris Lang committed Aug 6, 2012
1 parent e59c19d commit cc22139
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions samples/Scrumptious/scrumptious/SCViewController.m
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion src/FBPlacePickerCacheDescriptor.m
Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit cc22139

Please sign in to comment.