GMSAutocompleteFetcher.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //
  2. // GMSAutocompleteFetcher.h
  3. // Google Places SDK for iOS
  4. //
  5. // Copyright 2016 Google LLC
  6. //
  7. // Usage of this SDK is subject to the Google Maps/Google Earth APIs Terms of
  8. // Service: https://developers.google.com/maps/terms
  9. //
  10. #import "GMSAutocompleteFilter.h"
  11. #import "GMSPlacesDeprecationUtils.h"
  12. @class GMSAutocompletePrediction;
  13. @class GMSAutocompleteSessionToken;
  14. NS_ASSUME_NONNULL_BEGIN
  15. /**
  16. * Protocol for objects that can receive callbacks from GMSAutocompleteFetcher
  17. */
  18. @protocol GMSAutocompleteFetcherDelegate <NSObject>
  19. @required
  20. /**
  21. * Called when autocomplete predictions are available.
  22. * @param predictions an array of GMSAutocompletePrediction objects.
  23. */
  24. - (void)didAutocompleteWithPredictions:(NSArray<GMSAutocompletePrediction *> *)predictions;
  25. /**
  26. * Called when an autocomplete request returns an error.
  27. * @param error the error that was received.
  28. */
  29. - (void)didFailAutocompleteWithError:(NSError *)error;
  30. @end
  31. /**
  32. * GMSAutocompleteFetcher is a wrapper around the lower-level autocomplete APIs that encapsulates
  33. * some of the complexity of requesting autocomplete predictions as the user is typing. Calling
  34. * sourceTextHasChanged will generally result in the provided delegate being called with
  35. * autocomplete predictions for the queried text, with the following provisos:
  36. *
  37. * - The fetcher may not necessarily request predictions on every call of sourceTextHasChanged if
  38. * several requests are made within a short amount of time.
  39. * - The delegate will only be called with prediction results if those predictions are for the
  40. * text supplied in the most recent call to sourceTextHasChanged.
  41. */
  42. @interface GMSAutocompleteFetcher : NSObject
  43. /**
  44. * Initialize the fetcher.
  45. *
  46. * @param filter The filter to apply to the results. This parameter may be nil.
  47. */
  48. - (instancetype)initWithFilter:(nullable GMSAutocompleteFilter *)filter NS_DESIGNATED_INITIALIZER;
  49. /** Delegate to be notified with autocomplete prediction results. */
  50. @property(nonatomic, weak, nullable) id<GMSAutocompleteFetcherDelegate> delegate;
  51. /** Filter to apply to autocomplete suggestions (can be nil). */
  52. @property(nonatomic, strong, nullable) GMSAutocompleteFilter *autocompleteFilter;
  53. /**
  54. * Provide a |GMSAutocompleteSessionToken| for tracking the specific autocomplete query flow.
  55. */
  56. - (void)provideSessionToken:(nullable GMSAutocompleteSessionToken *)sessionToken;
  57. /**
  58. * Notify the fetcher that the source text to autocomplete has changed.
  59. *
  60. * This method should only be called from the main thread. Calling this method from another thread
  61. * will result in undefined behavior. Calls to |GMSAutocompleteFetcherDelegate| methods will also be
  62. * called on the main thread.
  63. *
  64. * This method is non-blocking.
  65. * @param text The partial text to autocomplete.
  66. */
  67. - (void)sourceTextHasChanged:(nullable NSString *)text;
  68. @end
  69. NS_ASSUME_NONNULL_END