Created
November 20, 2017 10:08
-
-
Save dratwas/92982973e974aaf066fedcc7406a5ac0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[self sendEventWithName:@"onSessionConnect" body:@{@"sessionId": session.sessionId}]; |
@PerspectivesLab https://facebook.github.io/react-native/docs/native-modules-ios#sending-events-to-javascript
RCT_EXPORT_METHOD(addEvent:(NSString *)name params:(NSDictionary *)params) {
NSString *site = [RCTConvert NSString:params[@"site"]];
[self notificationEvent];
RCTLogInfo(@"Pretending to create an event %@ at %@", name, site);
}
- (NSArray<NSString *> *)supportedEvents
{
return @[@"onSessionConnect"];
}
// Will be called when this module's first listener is added.
-(void)startObserving {
hasListeners = YES;
}
// Will be called when this module's last listener is removed, or on dealloc.
-(void)stopObserving {
hasListeners = NO;
}
- (void) notificationEvent {
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(sendEvent:) name:@"Eezy" object:@"my object"];
[[NSNotificationCenter defaultCenter]postNotificationName:@"Eezy" object:@"my object" userInfo:@{@"Status": @"Success"}];
}
- (void)sendEvent:(NSNotification *)notification {
if (hasListeners) {
RCTLogInfo(@"Event recieved.");
[self sendEventWithName:@"onSessionConnect" body:@{@"body": notification.name}];
} else {
RCTLogInfo(@"Event stoped.");
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
from where do you call this function? its inaccessible from other implementation or classes...