Detect whether iPad supports sim card programmatically - ios

Currently, I have an app that shows the 3G data / Wifi used by the user since the last reboot.
What I want to do is, if the app is running on an iPad which doesn’t support SIM card, I want to hide certain statistics shown to the user.
Is it somehow possible to detect whether the current iOS device supports a sim card or not?

As far as I know, you cannot detect if the SIM card is installed. You can only determine if a WWAN connection is available using Reachability or you can use CTCarrier
#import CoreTelephony;
-(BOOL)hasCellularCoverage
{
CTTelephonyNetworkInfo *networkInfo = [CTTelephonyNetworkInfo new];
CTCarrier *carrier = [networkInfo subscriberCellularProvider];
if (!carrier.isoCountryCode) {
NSLog(#"No sim present Or No cellular coverage or phone is on airplane mode.");
return NO;
}
return YES;
}

Related

is it possible to connect bluetooth device, without pairing them in iOS?

The question is not for BLE device, its just normal bluetooth device.
currently my code works like this,
I call the function :
[[EAAccessoryManager sharedAccessoryManager] showBluetoothAccessoryPickerWithNameFilter:nil completion:^(NSError *error)
{
}];
}
and it opens the popup with list of available Bluetooth device, then i click on my desired device and get an object and go ahead.
Is there any way that i can skip this picker step and directly get an object of my device?
No, it's not possible to connect without pairing first. The first time, you must have the user pair with the device either from the Settings app or from the picker. After the first pairing, however, you can skip the picker and get an EAAccesory * for your accessory, if the accessory is already connected to the iOS device. Here is how you can query the list of connected accessories:
NSArray<EAAccessory *> *connectedAccessories = [EAAccessoryManager sharedAccessoryManager].connectedAccessories;
for (EAAccessory *accessory in connectedAccessories) {
// Implement needed filter to recognize your device.
// You can use for instance accessory.protocolStrings
// The MAC address is available with [accessory valueForKey:#"macAddress"]
}
With the EAAccessory framework you can't initiate a connection to a device programmatically. For subsequent connections, you can have your device reconnect to the last connected device (if you control the firmware). This will trigger the EAAccessoryDidConnectNotification if your app is in the foreground, otherwise it will queue the notification and update the list of connected accessories.

Objective C fetch MobileOperator name via Simulator

I have tried fetching carrier name by using the below code via iphone and ipad simulators with XCode7.3.1.But this return (null)
CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = [networkInfo subscriberCellularProvider];
// Get carrier name
carrierName = [carrier carrierName];
Can anyone help me to find carrier name via simulator, without changing XCode system files
while we fetching the carrier value in the simulator it returns null only(because for carrier value we requires simcard),so we have to set the carrier value in the info.plist manually,i hope this answer will help you
In Apple Docs
if a user swaps the device’s SIM card with one from another provider,
while your application is running. This class also gives you access to
the CTCarrier object, which contains information about the user’s home
cellular service provider.
Since simulator doesn't have cellular service provider carrier will be nil.
You need device with sim card inserted to get any value.
No, In simulator it is not possible to get the carrierName. You need device with SIM card.
You will have to use a device to get this info. According to documentation:
If you configure a device for a carrier and then remove the SIM card,
this property retains the name of the carrier. The value for this
property is nil if the device was never configured for a carrier.
So nil in simulator is an expected return value.

How to check if Bluetooth is enabled via iOS External Accessory Framework?

I am writing an iOS-based program that interacts with a Bluetooth device via the External Accessory Framework. I would like to determine ahead of time if Bluetooth is even enabled before attempting to connect. Unfortunately, I don't see anything in the External Accessory Framework documentation that allows me to do this.
After checking the docs for the [EAAccessoryManager][1], the closest I can find is to check the [connectedAccessories][1] list to see if any devices are currently connected. However, this doesn't directly indicate the Bluetooth adapter's status.
There are plenty of examples on SO pertaining to Core Bluetooth and Bluetooth LE. I'm specifically looking for a solution related to the External Accessory Framework.
This is not possible with the ExternalAccessory framework. You should use CoreBluetooth, which can give you the information you need on devices that have BLE hardware, i.e. everything released after 2011. The fact that you are using ExternalAccessory for communication with your device does not prevent you from also using CoreBluetooth just for the purpose of knowing whether Bluetooth is turned on.
For older devices there is no way to get this info with public APIs, however if you are not intending to publish your app on the App Store you can use the private BluetoothManager framework.
To get the info with CoreBluetooth you will need to instanciate a CBCentralManager instance, for example like this :
centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:nil];
and then implement the following delegate method to get the relevant info :
- (void)centralManagerDidUpdateState:(CBCentralManager *)central {
BOOL bleAvailable = central.state != CBCentralManagerStateUnsupported;
if (bleAvailable) {
BOOL bluetoothTurnedOn = central.state != CBCentralManagerStatePoweredOff;
// Do something with the info
}
else {
// Out of luck... We won't be able to determine whether BT is on or off
}
}

Get current type of internet connection

I want to get the technology of radio access (internet connection), so detect if the device is connected to Wifi or WWAN connection (and in this case, which type of WWAN : GPRS, EGDE, 3G, 3G+, 3G++, or 4G).
Does CTTelephonyNetworkInfo works for iPhone and iPad on iOS7.1 ?
I've tried to detect a Wifi connection on an iPad but I print a null result.
This is my code :
CTTelephonyNetworkInfo *telephonyInfo = [CTTelephonyNetworkInfo new];
NSLog(#"Current Radio Access Technology: %#", telephonyInfo.currentRadioAccessTechnology);
Someone can told me why ? I'm not sure to understand everything about this...
Thanks for your help
(Source : http://www.objc.io/issue-5/iOS7-hidden-gems-and-workarounds.html, section "Know your Radio")
That's because currentRadioAccessTechnology will return the radio access technology (not whether it's Wifi or WWAN). An example of return value is CTRadioAccessTechnologyLTE.
To get informed about whether your app is connect to Wifi or WWAN, you should use Reachability.
There are several implementations available.

Is it possible to detect LTE connection using iOS SDK?

I'm using the reachability API to detect my current connection, but I can only distinguish between WIFI and 3G.
I get the following flags:
LTE: kSCNetworkReachabilityFlagsIsLocalAddress|kSCNetworkReachabilityFlagsIsWWAN|kSCNetworkReachabilityFlagsTransientConnection|kSCNetworkReachabilityFlagsReachable
WIFI: kSCNetworkReachabilityFlagsIsDirect|kSCNetworkReachabilityFlagsReachable
The problem is that LTE returns the same flags as a 3G connection. Is there any way to determine whether the user currently has LTE or 3G?
As of iOS 7, you can find this out using the currentRadioAccessTechnology property of CTTelephonyNetworkInfo in the CoreTelephony framework.
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
CTTelephonyNetworkInfo *networkInfo = [CTTelephonyNetworkInfo new];
if ([networkInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyLTE]) {
// ...
}
I wonder if this hidden Core Telephony API can provide you with enough info for you to determine whether you're attached to an LTE or a slower technology.
CTRegistrationGetCurrentMaxAllowedDataRate();
It might be worth experimenting with.
More about using private APIs here: iPhone mobile number using Core telephony
However, I've read that your app will be rejected by apple if you use private APIs.

Resources