jordanbyron / react-native-quick-actions

A react-native interface for Touch 3D home screen quick actions
MIT License
1.06k stars 93 forks source link

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

Closed rsml closed 4 years ago

rsml commented 5 years ago

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 commented 5 years ago

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 commented 4 years ago

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

rsml commented 4 years ago

@jordanbyron Sure thing. I submitted a pull request.

jordanbyron commented 4 years ago

Thanks @rsml