FIRMessagingAuthService.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright 2019 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. #import "FirebaseMessaging/Sources/Token/FIRMessagingCheckinService.h"
  18. NS_ASSUME_NONNULL_BEGIN
  19. @class FIRMessagingCheckinPreferences;
  20. @class FIRMessagingCheckinStore;
  21. /**
  22. * @related FIRInstanceIDCheckinService
  23. *
  24. * The completion handler invoked once the fetch from Checkin server finishes.
  25. * For successful fetches we returned checkin information by the checkin service
  26. * and `nil` error, else we return the appropriate error object as reported by the
  27. * Checkin Service.
  28. *
  29. * @param checkinPreferences The checkin preferences as fetched from the server.
  30. * @param error The error object which fetching GServices data.
  31. */
  32. typedef void (^FIRMessagingDeviceCheckinCompletion)(
  33. FIRMessagingCheckinPreferences *_Nullable checkinPreferences, NSError *_Nullable error);
  34. /**
  35. * FIRMessagingAuthService is responsible for retrieving, caching, and supplying checkin info
  36. * for the rest of Instance ID. A checkin can be scheduled, meaning that it will keep retrying the
  37. * checkin request until it is successful. A checkin can also be requested directly, with a
  38. * completion handler.
  39. */
  40. @interface FIRMessagingAuthService : NSObject
  41. /**
  42. * Initializes the auth service given a store (which provides the local caching of checkin info).
  43. * This initializer will create its own instance of FIRMessagingCheckinService.
  44. */
  45. - (instancetype)initWithCheckinStore:(FIRMessagingCheckinStore *)store;
  46. #pragma mark - Checkin Service
  47. /**
  48. * Checks if the current deviceID and secret are valid or not.
  49. *
  50. * @return YES if the checkin credentials are valid else NO.
  51. */
  52. - (BOOL)hasValidCheckinInfo;
  53. /**
  54. * Fetch checkin info from the server. This would usually refresh the existing
  55. * checkin credentials for the current app.
  56. *
  57. * @param handler The completion handler to invoke once the checkin info has been
  58. * refreshed.
  59. */
  60. - (void)fetchCheckinInfoWithHandler:(nullable FIRMessagingDeviceCheckinCompletion)handler;
  61. /**
  62. * Schedule checkin. Will hit the network only if the currently loaded checkin
  63. * preferences are stale.
  64. *
  65. * @param immediately YES if we want it to be scheduled immediately else NO.
  66. */
  67. - (void)scheduleCheckin:(BOOL)immediately;
  68. /**
  69. * Returns the checkin preferences currently loaded in memory. The Checkin preferences
  70. * can be either valid or invalid.
  71. *
  72. * @return The checkin preferences loaded in memory.
  73. */
  74. - (FIRMessagingCheckinPreferences *)checkinPreferences;
  75. /**
  76. * Cancels any ongoing checkin fetch, if any.
  77. */
  78. - (void)stopCheckinRequest;
  79. /**
  80. * Resets the checkin information.
  81. *
  82. * @param handler The callback handler which is invoked when checkin reset is complete,
  83. * with an error if there is any.
  84. */
  85. - (void)resetCheckinWithHandler:(void (^)(NSError *error))handler;
  86. @end
  87. NS_ASSUME_NONNULL_END