mirror of
https://github.com/deneraraujo/OpenVPNAdapter.git
synced 2026-01-31 00:00:06 +08:00
Implement internet reachability monitor
This commit is contained in:
@@ -11,8 +11,6 @@
|
||||
|
||||
@interface OpenVPNReachability (Internal)
|
||||
|
||||
@property OpenVPNReachabilityTracker *reachabilityTracker;
|
||||
|
||||
- (void)updateReachabilityStatus:(OpenVPNReachabilityStatus)status;
|
||||
|
||||
@end
|
||||
|
||||
@@ -12,8 +12,9 @@
|
||||
@interface OpenVPNReachability : NSObject
|
||||
|
||||
@property (readonly, nonatomic) OpenVPNReachabilityStatus reachabilityStatus;
|
||||
@property (copy, nonatomic) void (^ _Nullable reachabilityStatusChangedBlock)(OpenVPNReachabilityStatus reachabilityStatus);
|
||||
|
||||
- (nonnull instancetype)initWatchingWWAN:(BOOL)watchWWAN watchingWiFi:(BOOL)watchWiFi;
|
||||
- (nonnull instancetype)init;
|
||||
|
||||
- (void)startTracking;
|
||||
- (void)stopTracking;
|
||||
|
||||
@@ -9,13 +9,49 @@
|
||||
#import "OpenVPNReachability.h"
|
||||
#import "OpenVPNReachability+Internal.h"
|
||||
|
||||
@interface OpenVPNReachability () {
|
||||
OpenVPNReachabilityStatus _reachabilityStatus;
|
||||
}
|
||||
|
||||
@property (assign, nonatomic) OpenVPNReachabilityTracker *reachabilityTracker;
|
||||
|
||||
@end
|
||||
|
||||
@implementation OpenVPNReachability (Internal)
|
||||
|
||||
|
||||
- (void)updateReachabilityStatus:(OpenVPNReachabilityStatus)status {
|
||||
_reachabilityStatus = status;
|
||||
if (self.reachabilityStatusChangedBlock) {
|
||||
self.reachabilityStatusChangedBlock(status);
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation OpenVPNReachability
|
||||
|
||||
- (OpenVPNReachabilityStatus)reachabilityStatus {
|
||||
return _reachabilityStatus;
|
||||
}
|
||||
|
||||
- (nonnull instancetype)init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.reachabilityTracker = new OpenVPNReachabilityTracker(true, false, (__bridge void *)self);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)startTracking {
|
||||
self.reachabilityTracker->reachability_tracker_schedule();
|
||||
}
|
||||
|
||||
- (void)stopTracking {
|
||||
self.reachabilityTracker->reachability_tracker_cancel();
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
delete self.reachabilityTracker;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user