diff --git a/ios/RCTSpotlightSearch/RCTSpotlightSearch/RCTSpotlightSearch.m b/ios/RCTSpotlightSearch/RCTSpotlightSearch/RCTSpotlightSearch.m index 4708f9f..7393420 100644 --- a/ios/RCTSpotlightSearch/RCTSpotlightSearch/RCTSpotlightSearch.m +++ b/ios/RCTSpotlightSearch/RCTSpotlightSearch/RCTSpotlightSearch.m @@ -21,6 +21,7 @@ @interface RCTSpotlightSearch () @property (nonatomic, strong) id continueUserActivityObserver; @property (nonatomic, strong) id bundleDidLoadObserver; @property (nonatomic, copy) NSString *initialIdentifier; +@property (nonatomic, assign) BOOL hasListeners; @end @@ -68,6 +69,14 @@ - (dispatch_queue_t)methodQueue { return dispatch_get_main_queue(); } +- (void)startObserving { + self.hasListeners = YES; +} + +- (void)stopObserving { + self.hasListeners = NO; +} + - (void)drainActivityQueue { NSMutableArray *activityQueue = [[self class] activityQueue]; @@ -105,6 +114,10 @@ - (void)handleContinueUserActivity:(NSUserActivity *)userActivity { self.initialIdentifier = uniqueItemIdentifier; + if (!self.hasListeners) { + return; + } + [self sendEventWithName:kSpotlightSearchItemTapped body:uniqueItemIdentifier]; }