In React Native, is there a way to send NSNotifications without using Native Modules?

I am looking for ways to write simple user interface handler code in Objective-C that does not require a callback.

0
source share
1 answer

As far as I know, there is no such module. You can make your own. It is very simple.

The code:

// NotificationManager.h #import <Foundation/Foundation.h> #import "RCTBridgeModule.h" @interface NotificationManager : NSObject <RCTBridgeModule> @end // NotificationManager.m #import "NotificationManager.h" @implementation NotificationManager RCT_EXPORT_MODULE() RCT_EXPORT_METHOD(postNotification:(NSString *)name) { [[NSNotificationCenter defaultCenter] postNotificationName:name object:nil userInfo:nil]; } @end 

Now you can just send a notification from JavaScript

 var NotificationManager = require('react-native').NativeModules.NotificationManager; NotificationManager.postNotification("TestEvent") 
+4
source

All Articles