React Native instantiate singleton native module in Swift

Viewed 428

I have a CloudStorage native module that will be available on NativeModules.CloudStorage. I know the module is instantiated as a singleton by React Native. Is there a way to access the same singleton from my application delegate, like this:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler {
 ...
 [[CloudStorage sharedInstance] handleNotification]
}

From my understanding, at the time when we call sharedInstance, React Native have already created a singleton instance somewhere by calling [CloudStorage new], which will be different from the [CloudStorage sharedInstance] What's the best way to create a singleton native module that you can also access via the objective-c/swift side?

0 Answers
Related