Created
March 18, 2015 20:18
-
-
Save jmagnuss/e2e512281cda025149c2 to your computer and use it in GitHub Desktop.
Get carrier on Android and iOS
This file contains hidden or 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
| /* ANDROID */ | |
| public static String getCarrier(Context mContext) | |
| { | |
| TelephonyManager manager = (TelephonyManager)mContext.getSystemService(Context.TELEPHONY_SERVICE); | |
| String carrierName = manager.getNetworkOperatorName(); | |
| if (carrierName.length() > 0) { | |
| return carrierName; | |
| } else { | |
| return "Unknown"; | |
| } | |
| } | |
| /* iOS */ | |
| +(NSString*)getCarrier | |
| { | |
| CTTelephonyNetworkInfo *netinfo = [[CTTelephonyNetworkInfo alloc] init]; | |
| CTCarrier *carrier = [netinfo subscriberCellularProvider]; | |
| NSString *carrierName = [carrier carrierName]; | |
| if (carrierName) | |
| return carrierName; | |
| return @"Unknown"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment