Skip to content
This repository has been archived by the owner on Apr 15, 2023. It is now read-only.

iOS warning: [setShortcutItems()] UI API called on a background thread #87

Closed
rsml opened this issue Jun 6, 2019 · 4 comments · Fixed by #91
Closed

iOS warning: [setShortcutItems()] UI API called on a background thread #87

rsml opened this issue Jun 6, 2019 · 4 comments · Fixed by #91

Comments

@rsml
Copy link

rsml commented Jun 6, 2019

I have an app where on iOS it opens in response to clicking a universal link. Then I immediately call setShortcutItems().

I get this warning in the console, but no crash:

Main Thread Checker: UI API called on a background thread: -[UIApplication setShortcutItems:]
PID: 2685, TID: 895698, Thread name: (none), Queue name: com.facebook.react.RNQuickActionManagerQueue, QoS: 0

I'm calling setShortcutItems() from inside javascript so I'm not sure what's causing it to run on a background thread.

I'm thinking you might need to add a Dispatch.main.async on iOS for cases when it's running in a background thread.

@rsml
Copy link
Author

rsml commented Jun 6, 2019

My coworker suggested this change:

In RNQuickActionManager.m

Change:

RCT_EXPORT_METHOD(setShortcutItems:(NSArray *) shortcutItems)
{
    NSArray *dynamicShortcuts = [self dynamicShortcutItemsForPassedArray:shortcutItems];
    [UIApplication sharedApplication].shortcutItems = dynamicShortcuts;
}

To:

RCT_EXPORT_METHOD(setShortcutItems:(NSArray *) shortcutItems)
{
  dispatch_async(dispatch_get_main_queue(), ^{
    NSArray *dynamicShortcuts = [self dynamicShortcutItemsForPassedArray:shortcutItems];
    [UIApplication sharedApplication].shortcutItems = dynamicShortcuts;
  });
}

@jordanbyron
Copy link
Owner

@rsml great! Would you be willing to put this together in a PR?

@rsml
Copy link
Author

rsml commented Nov 23, 2019

@jordanbyron Sure thing. I submitted a pull request.

jordanbyron added a commit that referenced this issue Nov 24, 2019
…-thread

Fix setShortcutItems UI API called on a background thread (#87)
@jordanbyron
Copy link
Owner

Thanks @rsml

greedbell pushed a commit to shimo-react-native/react-native-quick-actions that referenced this issue Dec 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants