mirror of
https://github.com/deneraraujo/OpenVPNAdapter.git
synced 2026-04-24 00:00:05 +08:00
Implement internet reachability monitor
This commit is contained in:
@@ -11,8 +11,6 @@
|
|||||||
|
|
||||||
@interface OpenVPNReachability (Internal)
|
@interface OpenVPNReachability (Internal)
|
||||||
|
|
||||||
@property OpenVPNReachabilityTracker *reachabilityTracker;
|
|
||||||
|
|
||||||
- (void)updateReachabilityStatus:(OpenVPNReachabilityStatus)status;
|
- (void)updateReachabilityStatus:(OpenVPNReachabilityStatus)status;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -12,8 +12,9 @@
|
|||||||
@interface OpenVPNReachability : NSObject
|
@interface OpenVPNReachability : NSObject
|
||||||
|
|
||||||
@property (readonly, nonatomic) OpenVPNReachabilityStatus reachabilityStatus;
|
@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)startTracking;
|
||||||
- (void)stopTracking;
|
- (void)stopTracking;
|
||||||
|
|||||||
@@ -9,13 +9,49 @@
|
|||||||
#import "OpenVPNReachability.h"
|
#import "OpenVPNReachability.h"
|
||||||
#import "OpenVPNReachability+Internal.h"
|
#import "OpenVPNReachability+Internal.h"
|
||||||
|
|
||||||
|
@interface OpenVPNReachability () {
|
||||||
|
OpenVPNReachabilityStatus _reachabilityStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
@property (assign, nonatomic) OpenVPNReachabilityTracker *reachabilityTracker;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
@implementation OpenVPNReachability (Internal)
|
@implementation OpenVPNReachability (Internal)
|
||||||
|
|
||||||
|
- (void)updateReachabilityStatus:(OpenVPNReachabilityStatus)status {
|
||||||
|
_reachabilityStatus = status;
|
||||||
|
if (self.reachabilityStatusChangedBlock) {
|
||||||
|
self.reachabilityStatusChangedBlock(status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation OpenVPNReachability
|
@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
|
@end
|
||||||
|
|||||||
Reference in New Issue
Block a user