现在我正在使用带有以下代码的本机模块:
RCT_EXPORT_METHOD(getSignalStrength:
(RCTResponseSenderBlock)callback) {
UIApplication *app = [UIApplication sharedApplication];
NSArray *subviews = [[[app valueForKey:@"statusBar"] valueForKey:@"foregroundView"] subviews];
NSString *wifiNetworkItemView = nil;
for (id subview in subviews) {
if([subview isKindOfClass:[NSClassFromString(@"UIStatusBarDataNetworkItemView") class]]) {
wifiNetworkItemView = subview;
}
}
int wifiSignalStrength = [[wifiNetworkItemView valueForKey:@"wifiStrengthRaw"] intValue];
NSString *strengthString = [NSString stringWithFormat:@"%d", wifiSignalStrength];
callback(@[strengthString]);
}
在JavaScript中,我以这种方式调用此函数:
CustomModule.getSignalStrength(sig => {
signalStrength = Number(sig)
this.setSignalValues(signalStrength)
})
但是我需要这些信息是实时的,而不仅仅是一个电话。我不想使用任何计时器。我希望有一些听众。但是怎么做呢?