FIRIAMDisplayCheckOnAnalyticEventsFlow.m 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright 2017 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 <FirebaseAnalyticsInterop/FIRAnalyticsInterop.h>
  17. #import <FirebaseAnalyticsInterop/FIRAnalyticsInteropListener.h>
  18. #import <FirebaseCore/FIRLogger.h>
  19. #import "FIRCore+InAppMessaging.h"
  20. #import "FIRIAMDisplayCheckOnAnalyticEventsFlow.h"
  21. #import "FIRIAMDisplayExecutor.h"
  22. #import "FIRInAppMessagingPrivate.h"
  23. @interface FIRIAMDisplayCheckOnAnalyticEventsFlow () <FIRAnalyticsInteropListener>
  24. @end
  25. @implementation FIRIAMDisplayCheckOnAnalyticEventsFlow {
  26. dispatch_queue_t eventListenerQueue;
  27. }
  28. - (void)start {
  29. @synchronized(self) {
  30. if (eventListenerQueue == nil) {
  31. eventListenerQueue =
  32. dispatch_queue_create("com.google.firebase.inappmessage.firevent_listener", NULL);
  33. }
  34. FIRLogDebug(kFIRLoggerInAppMessaging, @"I-IAM140002",
  35. @"Start observing Firebase Analytics events for rendering messages.");
  36. [[FIRInAppMessaging inAppMessaging].analytics registerAnalyticsListener:self
  37. withOrigin:@"fiam"];
  38. }
  39. }
  40. - (void)messageTriggered:(NSString *)name parameters:(NSDictionary *)parameters {
  41. // Dispatch to a serial queue eventListenerQueue to avoid the complications that two
  42. // concurrent Firebase Analytics events triggering the
  43. // checkAndDisplayNextContextualMessageForAnalyticsEvent flow concurrently.
  44. dispatch_async(self->eventListenerQueue, ^{
  45. [self.displayExecutor checkAndDisplayNextContextualMessageForAnalyticsEvent:name];
  46. });
  47. }
  48. - (void)stop {
  49. FIRLogDebug(kFIRLoggerInAppMessaging, @"I-IAM140003",
  50. @"Stop observing Firebase Analytics events for display check.");
  51. @synchronized(self) {
  52. [[FIRInAppMessaging inAppMessaging].analytics unregisterAnalyticsListenerWithOrigin:@"fiam"];
  53. }
  54. }
  55. @end