Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getter for cellular connection type #144

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Reachability.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ typedef NS_ENUM(NSInteger, NetworkStatus) {
ReachableViaWWAN = 1
};

typedef NS_ENUM(NSUInteger, CellularConnectionType) {
CellularConnectionTypeNone,
CellularConnectionTypeGPRS,
CellularConnectionTypeEdge,
CellularConnectionType3G,
CellularConnectionType4G
};

@class Reachability;

typedef void (^NetworkReachable)(Reachability * reachability);
Expand Down Expand Up @@ -95,6 +103,7 @@ typedef void (^NetworkReachability)(Reachability * reachability, SCNetworkConnec
-(BOOL)isInterventionRequired;

-(NetworkStatus)currentReachabilityStatus;
-(CellularConnectionType)currentCellularConnectionType __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_7_0);
-(SCNetworkReachabilityFlags)reachabilityFlags;
-(NSString*)currentReachabilityString;
-(NSString*)currentReachabilityFlags;
Expand Down
27 changes: 27 additions & 0 deletions Reachability.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF

#import "Reachability.h"

#import <CoreTelephony/CTTelephonyNetworkInfo.h>
#import <sys/socket.h>
#import <netinet/in.h>
#import <netinet6/in6.h>
Expand Down Expand Up @@ -83,6 +84,26 @@ static void TMReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkRea
}
}

static CellularConnectionType cellularConnectionType(NSString *type) {
if (!type) {
return CellularConnectionTypeNone;
}

return [@{
CTRadioAccessTechnologyGPRS : @(CellularConnectionTypeGPRS),
CTRadioAccessTechnologyEdge : @(CellularConnectionTypeEdge),
CTRadioAccessTechnologyWCDMA : @(CellularConnectionType3G),
CTRadioAccessTechnologyHSDPA : @(CellularConnectionType3G),
CTRadioAccessTechnologyHSUPA : @(CellularConnectionType3G),
CTRadioAccessTechnologyCDMA1x : @(CellularConnectionTypeEdge),
CTRadioAccessTechnologyCDMAEVDORev0 : @(CellularConnectionType3G),
CTRadioAccessTechnologyCDMAEVDORevA : @(CellularConnectionType3G),
CTRadioAccessTechnologyCDMAEVDORevB : @(CellularConnectionType3G),
CTRadioAccessTechnologyeHRPD : @(CellularConnectionType3G),
CTRadioAccessTechnologyLTE : @(CellularConnectionType4G),
}[type] integerValue];
}


@implementation Reachability

Expand Down Expand Up @@ -432,6 +453,12 @@ -(NSString*)currentReachabilityFlags
return reachabilityFlags([self reachabilityFlags]);
}

#pragma mark - Cellular connection type

-(CellularConnectionType)currentCellularConnectionType {
return cellularConnectionType([CTTelephonyNetworkInfo new].currentRadioAccessTechnology);
}

#pragma mark - Callback function calls this method

-(void)reachabilityChanged:(SCNetworkReachabilityFlags)flags
Expand Down
2 changes: 1 addition & 1 deletion Reachability.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ EOF

Pod::Spec.new do |s|
s.name = 'Reachability'
s.version = '3.2'
s.version = '3.3'
s.summary = 'ARC and GCD Compatible Reachability Class for iOS and OS X. Drop in replacement for Apple Reachability.'

s.homepage = 'https://github.com/tonymillion/Reachability'
Expand Down