是否反应原生模块发送事件到javascript文档是否正确?
问题描述:
在Facebook的doc它说是否反应原生模块发送事件到javascript文档是否正确?
- (void)calendarEventReminderReceived:(NSNotification *)notification
{
NSString *eventName = notification.userInfo[@"name"];
[self.bridge.eventDispatcher sendAppEventWithName:@"EventReminder"
body:@{@"name": eventName}];
}
JavaScript代码可以订阅这些事件:
var subscription = DeviceEventEmitter.addListener(
'EventReminder',
(reminder) => console.log(reminder.name)
);
但我永远不能得到这个工作。这应该是sendDeviceEventWithName吗?也应该本地模块总是单身?
答
目前,没有。请看到这个问题:
https://github.com/facebook/react-native/issues/394
更改例如Objective-C的调用sendDeviceEventWithName 而不是sendAppEventWithName解决了这个问题。
这似乎证实了你的建议。有一个拉请求等待被合并为这样:
酷,谢谢。在我更改为sendDeviceEventWithName后,它似乎工作正常。 – Matthew 2015-04-04 17:35:47
我实际上无法得到这个工作我自己!有什么机会可以将您的(简化)代码发布到某个地方吗? – 2015-04-04 18:31:16
诀窍是让你的natvie模块成为一个单身人士。只需在您的实例中检查_bridge并确保它不是零。我不确定这是一个功能还是错误。 – Matthew 2015-04-06 05:52:32