FIRIAMDisplayCheckOnAnalyticEventsFlow.m 2.6 KB

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