dustturtle / realreachability Goto Github PK
View Code? Open in Web Editor NEWWe need to observe the REAL reachability of network. That's what RealReachability do.
License: MIT License
We need to observe the REAL reachability of network. That's what RealReachability do.
License: MIT License
use gcdsocket when close the socket ,receive curStateID is 3 and never resume,but the http is normal.
针对苹果iOS最新审核要求为应用兼容IPv6
RealReachability的init方法里
_hostForPing = kDefaultHost;这样写,没走- (void)setHostForPing:(NSString *)hostForPing这个方法,导致GPingHelper.host设置不成功,会在
1:延迟问题,我在didFinishLaunchingWithOptions [GLobalRealReachability startNotifier] 进入app没有及时获取网络信息(wifi环境)
2:网络明明正常链接 过了一会儿又变成RealStatusNotReachable
真机连上wifi设置代理后,应该为“伪连接”,但显示能够正常上网。。。。
运行demo,系统是9.3.1的iphone6,从底部拉出系统菜单,关闭wifi按钮,从wifi切换到4g,会出现提示RealReachabilityStatus4G,接着再次提示为Network unreachable!从底部拉出系统菜单,打开wifi按钮,从4G切换到wifi也会出现Network wifi! Free,再次提示为Network unreachable!原因是第一次正常,第二次就都是notreachable,反复较快切换,这种情况出现的频率较为高;尤其是从wifi切换到4g,状态出现错误的概率很大(现象同前面描述);
个人觉得正常情况下打印日志是为了调试和查看错误状态信息,RealReachability库的使用者只关心库是否正常响应,虽然生产环境去除了日志,但是在开发环境,对于多余正常的日志信息我们也不关心,反而会影响我们查看其它错误日志信息,看到那么多无用的日志,真的很烦。所以我建议作者做2个调整:
1、添加宏定义并用累似RRLog来替换RealReachability中的NSLog
2、提供一个日志开关,用于控制打印日志(默认关掉)。
1.我在正常WiFi和3G之间切换还算正常,当我通过代理链接的时候,网络的实时监测情况就不准,有两种情况:
a.我代理填了一个假的代理(连接了WiFi但不能上网的情况)之后再切换真的代理(连接了WiFi且能上网的情况),就会经常出错,返回的链接基本上都是WiFi链接正常;
b.我代理填了一个假的代理(连接了WiFi但不能上网的情况)之后再切换真的代理(连接了WiFi且能上网的情况),然后在真代理和3G之间切换,基本上也会经常出错;
I get the same crash dump a lot of times. Every time, the thread that this is being done is some background thread.
I noticed you are starting the pingFoundation
in main thread. Do we also need to stop
it in main thread?
The below is the dump of the crash generated by Hockey
Thread 11 Crashed:
0x0000000181e459cc CFRelease + 1128
0x00000001005f5ec0 -PingFoundation stopDataTransfer
0x00000001005f5efc -PingFoundation stop
0x00000001005f62c0 -PingHelper pingWithBlock:
0x00000001005f77a0 -RealReachability reachabilityWithBlock:
0x00000001005f7e40 __41-[RealReachability autoCheckReachability]_block_invoke (RealReachability.m:253)
0x00000001819b9630 _dispatch_call_block_and_release + 20
0x00000001819b95f0 _dispatch_client_callout + 12
0x00000001819c4e7c _dispatch_after_timer_callback + 88
0x00000001819b95f0 _dispatch_client_callout + 12
0x00000001819d0204 _dispatch_source_latch_and_call + 2552
0x00000001819bbae4 _dispatch_source_invoke + 804
0x00000001819c7504 _dispatch_root_queue_drain + 724
0x00000001819c7224 _dispatch_worker_thread3 + 108
0x0000000181bcd470 _pthread_wqthread + 1088
0x0000000181bcd020 start_wqthread + 0
"warning! reachState uncertain! state unmatched, treat as unreachable temporary"
And on Simulator and on device.
RealReachability *t=[[RealReachability alloc]init];
t.hostForPing=@"www.baidu.com";
[t startNotifier];
[t reachabilityWithBlock:^(ReachabilityStatus status) {
NSLog(@"status %ld",status);
}];
我利用上述代码,然后不停打开或者关闭网络,都没有打印出网络状态,这个如何解决?
我手机开了VPN,app就无法连接网络了?
问题描述:在某个页面注册监听,如果当前网络是3G并且开WIFI,那么会必然进入networkChanged,其实网络本身并没有发生变化,不应当进入networkChanged回调函数
iphone 5C 监听网络状态 返回的网络状态 不对 总返回没有网络 而手机可以访问其他网络
网络波动(并非切换网络方式),出现网络不可达,但是这是这一点不可达,未来的非常快的一个时间点恢复网络了,触发通知回调很慢(对于这一点的验证:我在网络不可达以后立马通过提供的block获取但网络状态是可达的)
代码如下:
@interface RRController ()
@Property (weak, nonatomic) IBOutlet UILabel statusLabel; /*< 网络状态视图 */
@implementation RRController
(void)viewDidLoad
{
[super viewDidLoad];
[self setupUIForRR];
}
(void)viewWillAppear:(BOOL)animated
{
[self refreshNetworkStatus];
}
(void)dealloc
{
BKLog(@"");
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
(IBAction)clickBntForRR:(id)sender
{
UIStoryboard *main = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *detailController = [main instantiateViewControllerWithIdentifier:@"RRDetailController"];
if (detailController)
{
[self.navigationController pushViewController:detailController animated:YES];
}
}
(void)applicationDidBecomeActive
{
[self refreshNetworkStatus];
}
(void)networkChanged:(NSNotification *)notification
{
RealReachability *reachability = (RealReachability *)notification.object;
ReachabilityStatus status = [reachability currentReachabilityStatus];
BKLog(@"status = %zd", status);
[self refreshStatusLabel:status];
}
(void)setupUIForRR
{
// notifications
// 监听网络状态
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter addObserver:self
selector:@selector(networkChanged:)
name:kRealReachabilityChangedNotification
object:nil];
// 监听程序获取焦点
[defaultCenter addObserver:self
selector:@selector(applicationDidBecomeActive)
name:UIApplicationDidBecomeActiveNotification
object:nil];
}
(void)refreshNetworkStatus
{
[[RealReachability sharedInstance] reachabilityWithBlock:^(ReachabilityStatus status) {
BKLog(@"status = %zd", status);
[self refreshStatusLabel:status];
}];
}
(void)refreshStatusLabel:(ReachabilityStatus)status
{
switch (status) {
case RealStatusNotReachable:
{
[_statusLabel setBackgroundColor:[UIColor yellowColor]];
[_statusLabel setText:@"无网络!"];
break;
}
case RealStatusViaWWAN:
{
[_statusLabel setBackgroundColor:[UIColor greenColor]];
[_statusLabel setText:@"手机网络!"];
break;
}
case RealStatusViaWiFi:
{
[_statusLabel setBackgroundColor:[UIColor greenColor]];
[_statusLabel setText:@"WiFi网络!"];
break;
}
default:
break;
}
}
配置HTTP代理后,将代理主机网络断开,检测不到真实网络变化。
Hi,
I have always wanted this. To be notified about true connections.
After finding this repo, I tried to add it to one of my existing projects. The project has many many dependencies which in turn have their own dependencies and from there it goes a downward spiral ... anyway, somewhere along the way, one of these projects has Reachability as its dependency. Now, I can't remove the main dependency (not for the time being at least).
When I added RealReachability to my project, i have faced a conflict between RealReachability and Reachability on the NetworkStatus
enum cases:
typedef NS_ENUM(NSInteger, NetworkStatus) {
// Apple NetworkStatus Compatible Names.
NotReachable = 0,
ReachableViaWiFi = 2,
ReachableViaWWAN = 1
};
Is it possible to change the enum cases for the unlucky guys like me who want to keep Reachability and RealReachability coexist in one project?
我用bridge在swift工程下使用,但总是用不起来,这个支持Swift模式下使用吗?还希望能够给个Swift下使用的例子。
我用Network Link Conditioner开启100%丢包, 貌似不会被当作无网络处理, 按道理这个时候应该是ping不通然后会触发无网络的通知才对.
当前存在网络连接 ReachabilityStatus status = [GLobalRealReachability currentReachabilityStatus];
status却变成RealStatusNotReachable,在3G4G和WiFi下都是这样
苹果官方Reachability已经可以直接检测设备联网状态,不在仅仅检测本地联网状态:
https://developer.apple.com/library/ios/samplecode/Reachability/Introduction/Intro.html
而且开代理时检测也可以正常的返回联网状态
i have wifi but it is Network unreachable. it has wifi then change to Network unreachable
如题,就是我有个4s,越狱的,ios7,有做一些判断网络环境的操作,然后经常就是连着wifi,开始调试,点击,点击某个按钮进行网络请求,然后就判断成为了不是wifi个2 G 3 G 4G 的那个选项,另外2个就是一个没联网一个未知嘛。我这是连着公司wifi的,所以不知道是什么情况,求大神指教?(这个判断网不对我就只有重新commen+r)
为什么切换网络到手机热点,没接收到网络变化通知?
你好
我在看了源码后,发现PingFoundation的start方法中
self.host是用CFHostCreateWithName方法生成的
我自己又加了用CFHostCreateWithAddress方法生成self.host
但是发现加了端口号以后,始终都是返回无连接状态
请问这个是为什么呢?
手机连接了imac的wifi热点,imac运行了Charles,手机把Charles设置为代理,手机端要设置服务器ip地址和端口,故意写错了服务器IP地址(模拟能链接wifi,但上不了外网的情形),手机safari是打不开网页的,Demo检测网络状态依然为wifi状态,用PingHelper 直接去ping www.baidu.com也显示成功;这种情形能有效监测到吗?
你好,感谢提供这么优秀的开源代码。在使用过程中,我发现在切换网络的时候有时(概率并不高)会接收到两次通知,而且第二次通知事件中获取到的网络连接状态是错误的。这种情况只出现在由无网络切换到有网络的时候,也就是说,从无网络切换到有网络时,先收到了一个网络变化通知,在这个通知事件中获取到的网络状态是“连接状态”,然后又收到了另一个网络变化通知,在这个通知事件中获取到的网络状态是“不可连接状态”,这会导致程序出现异常。我跟了下代码,发现用户在收起系统快捷操作面板(就是从屏幕底部滑出的那个面板)的时候会触发reachabilityWithBlock事件,在localConnectionChanged事件后面也有触发reachabilityWithBlock事件,有可能是reachabilityWithBlock中发出了重复的通知。不知道这是不是一个bug,还是我使用的方法有问题。
我在 appdelegate.m 中添加的检测网络状况变化的通知
联网状态下 当第一次断网后 提示 网络断开 正常
再次联网后 刷新页面 正常 但是会增加一个 网络断开 的提示
demo 中 联网 断网 联网 这三种状态改变 后 页面上的label中 显示顺序 network wifi free - network unreachable - network wifi free - network unreachable
这是为什么呢
如题
}
这个方法会调用多次。切换网络的时候
打开wifi,几乎每次都先回调wifi,然后回调无网络
关闭wifi,因为之前已经回调了无网络,不进行回调。
Hey,
Just out of curiosity, what are the benefits of using this over Reachability or SCNetworkReachability.
My impression is that this would allow for faster feedbacks into the connection status by using pinging, is that it?
Thanks!
我们使用这个库监控网络状态后,用户大量反馈没有网络。但用户都是有网络的。要么是 wifi,要么是4G 状态下面的。造成用户不能使用其他功能了。
GLobalRealReachability.autoCheckInterval = CGFLOAT_MAX;
如题。
I use Surge with shadowsocks protocol to proxy my network connection and it always tells network not reachable when Surge is ON while reachable when Surge is OFF.
我现在项目中官方的那个网络监控 是3.5版的,不兼容IPv6,也没在官网找到最新版本的下载地址,直搜索到你上传到GitHub上这个版本,看时间时最新的,而且还是你封装好的,所有想知道是否支持,项目中其他的兼容设置我都已经改好了。6月份还有新版本上传app store,望看到后回复,谢谢!~
快要把Ping的log移掉吗,以一个第三方库来说,这种log算是侵入式的了。
因为app里有三个Host地址想检测啊。但目前好像就只支持一个吧
在 pingWithBlock:(void (^)(BOOL isSuccess))completion
方法的completion
中调用pingWithBlock:
,第二次的block参数会在pingTimeOut之前被 [self.completionBlocks removeAllObjects]
删除,导致第二个completion不能被调用。
求修改,这个很影响体验,网速慢的时候被认为断网了
It tells me "No normal status matched, return unreachable temporary" when I debug my app on my phone, I have no idea, what's wrong with it
从无网络切换到WIFI时networkChanged方法的status等于NotReachable,可以来回切换测试一下哦
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.