Last active
November 22, 2020 18:13
-
-
Save username0x0a/e6310aa6c982dbd276621564b8ab0f57 to your computer and use it in GitHub Desktop.
UIDevice subclass for fetching real carrier display name – may differ from regular -carrierName for virtual operators etc.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation UIDevice (Utils) | |
- (NSString *)cellularCarrierName | |
{ | |
return [[[[CTTelephonyNetworkInfo alloc] init] subscriberCellularProvider] carrierName]; | |
} | |
- (NSString *)cellularCarrierDisplayedName | |
{ | |
static NSString *displayedName = nil; | |
static NSDate *lastUpdate = nil; | |
// Perform an update every hour | |
if (!lastUpdate || -[lastUpdate timeIntervalSinceNow] > 60*60) | |
{ | |
UIView *bar = nil; | |
SEL sel = NSSelectorFromString([ @[ @"status", @"Bar" ] componentsJoinedByString:@""]); | |
#pragma clang diagnostic push | |
#pragma clang diagnostic ignored "-Warc-performSelector-leaks" | |
if ([[UIApplication sharedApplication] respondsToSelector:sel]) | |
bar = [[UIApplication sharedApplication] performSelector:sel]; | |
#pragma clang diagnostic pop | |
bar = [bar viewForClass:NSClassFromString( | |
[ @[ @"UI", @"Status", @"BarService", @"ItemView" ] componentsJoinedByString:@""])]; | |
displayedName = [bar valueForKey:@"_serviceString"] ?: | |
[self cellularCarrierName]; | |
} | |
return displayedName; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment