File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -467,8 +467,13 @@ - (void)userActivityWillSave:(NSUserActivity *)userActivity {
467467#pragma mark Helper Methods
468468
469469- (UIViewController *)getActiveViewController {
470- UIViewController *rootViewController = [UIApplication sharedApplication ].keyWindow .rootViewController ;
471- return [self getActiveViewController: rootViewController];
470+ Class UIApplicationClass = NSClassFromString (@" UIApplication" );
471+ if (UIApplicationClass) {
472+ UIViewController *rootViewController = [UIApplication sharedApplication ].keyWindow .rootViewController ;
473+ return [self getActiveViewController: rootViewController];
474+ }
475+
476+ return nil ;
472477}
473478
474479- (UIViewController *)getActiveViewController : (UIViewController *)rootViewController {
@@ -488,6 +493,11 @@ - (void)indexUsingNSUserActivity:(NSDictionary *)params {
488493 self.userInfo [CSSearchableItemActivityIdentifier] = params[@" spotlightId" ];
489494
490495 UIViewController *activeViewController = [self getActiveViewController ];
496+
497+ if (!activeViewController) {
498+ // if no view controller, don't index. Current use case: iMessage extensions
499+ return ;
500+ }
491501 NSString *uniqueIdentifier = [NSString stringWithFormat: @" io.branch.%@ " , [[NSBundle mainBundle ] bundleIdentifier ]];
492502 // Can't create any weak references here to the userActivity, otherwise it will not index.
493503 activeViewController.userActivity = [[NSUserActivity alloc ] initWithActivityType: uniqueIdentifier];
You can’t perform that action at this time.
0 commit comments