Skip to content

Commit 032d1c3

Browse files
guangyaoguangyao
authored andcommitted
add 网络状态检测
1 parent 89efbf7 commit 032d1c3

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

AppCacheUtil.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,12 @@ export default class AppCacheUtil{
1717
static getCacheSize(){
1818
return RNNeteaseIm.getCacheSize();
1919
}
20+
21+
/**
22+
* 获取网络状态
23+
*/
24+
static getNetWorkStatus(){//0:无网络,1:有网络
25+
return RNNeteaseIm.getNetWorkStatus();
26+
}
2027
}
2128

ios/RNNeteaseIm/RNNeteaseIm/RNNeteaseIm.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,5 +655,24 @@ -(void)setSendState{
655655
};
656656
}
657657

658+
//开启录音权限
659+
RCT_EXPORT_METHOD(getNetWorkStatus:(RCTPromiseResolveBlock)resolve
660+
reject:(RCTPromiseRejectBlock)reject){
661+
UIApplication *app = [UIApplication sharedApplication];
662+
NSArray *children = [[[app valueForKeyPath:@"statusBar"] valueForKeyPath:@"foregroundView"] subviews];
663+
int type = 0;//0:无网络, 1:2G, 2:3G, 3:4G, 4:LTE准4G,5:wifi
664+
for (id child in children) {
665+
if ([child isKindOfClass:[NSClassFromString(@"UIStatusBarDataNetworkItemView") class]]) {
666+
type = [[child valueForKeyPath:@"dataNetworkType"] intValue];
667+
}
668+
}
669+
if (type) {
670+
resolve(@(1));
671+
}else{
672+
resolve(@(0));
673+
}
674+
675+
}
676+
658677

659678
@end

0 commit comments

Comments
 (0)