Get current type of internet connection - ios

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.

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.

How to check internet available to mobile packdata or not..?

Our app support offline and online
So every step we need to check internet available to network or not.
When we using Reachability class then wi-fi off/on check it properly.
And in another we are also use SimplePing it is also work properly with Wi-fi using ping to host.
We are also check ICMP socket programing for this but it is only support to wi-fi.
But when we are using mobile packetdata how can we check internet is available to mobile or not.
NSURL *scriptUrl = [NSURL URLWithString:#"http://google.co.in/"];
NSData *data = [NSData dataWithContentsOfURL:scriptUrl];
if (data)
NSLog(#"Device is connected to the internet");
else
NSLog(#"Device is not connected to the internet");
This is something that a OS detects itself or by the ISP. You can check whether the internet is available through WiFi, or through CellularData or some other medium.
Internet access will automatically disconnected if user has consumed the data.
You can not check this by writing code.

Connecting to other Bluetooth Device by BeeTee app

I need to implement a self bluetooth app to connect with all bluetooth devices to iPhone. I know it is not possible with CoreBluetooth framework.
I use private API and added header files of DeviceManager and BluetoothManager to private frameworks and downloaded BeeTee Project from here
This app runs and finds all bluetooth device near me but when I have tried to connect to a device by this code:
[self.bluetoothManager connectDevice:bluetoothDevice];
and this
[bluetoothDevice connect];
When a cell is selected, Both of above codes request to connect but BTM returns this message:
BeeTee[5473:60b] BTM: connection to service 0xffffffff on device "Nokia 500" F4:xx:xx:xx:xx:xx failed with error 109
What is error 109? Which would be set service number?
I guess I should pair devices before connecting but how can I do that?
I am just guessing, but I think the problem is that the BluetoothManager.framework is made for the External Accessory Program by Apple. And this allows (among others) SPP Bluetooth connection to certificated devices. But there is the problem: you need to have a device with a authentication chip inside.
I don't know on which level/layer Apple implemented the authentication, but I fear the did it one layer under the private framework BeeTee is using.
UPDATE: Maybe this is helpful for you:
BluetoothManager *bluetoothManager = //...
[bluetoothManager setDevicePairingEnabled:YES];
[bluetoothManager connectDevice:bluetoothDevice withServices:0x00002000];
Credits
BluetoothManager *bluetoothManager = //...
[bluetoothManager setDevicePairingEnabled:YES];
[btManager setPincode:#"111111" forDevice:bluetoothDevice.deviceRef];
//where 111111 is your device PIN
[bluetoothManager connectDevice:bluetoothDevice withServices:0x00002000];

Download content over wifi only or use both wifi and 3G network to download

I am implementing a method in iOS app that allow user to download content over WiFi only or use both WiFi and 3G network to download content from web server, my question is how to make switch that can be turn on and off for downloading WiFi or 3G only option? just like apple use it for iTunes Store content on iOS, so if user turn wifi only option on than content will only be downloaded using wifi network.
Should i be using Reachability class or something else?
The Reachability class can help you with this. Initialize it as needed for your connectivity, eg:
Reachability *reachability = [Reachability reachabilityWithHostName:#"www.google.com"];
You can now query the 'currentReachabilityStatus' property to determine if you are connected, and if WiFi is available.
NetworkStatus status = reachability.currentReachabilityStatus;
switch(status)
{
case ReachableViaWiFi:
// There's a wifi connection, go ahead and download
break;
case ReachableViaWWAN:
// There's only a cell connection, so you may or may not want to download
break;
case NotReachable:
// No connection at all! Bad signal, or perhaps airplane mode?
break;
}
Of course it's up to you to handle the states correctly in your application.
Also, you can change URLSessionConfiguration's property
var allowsCellularAccess: Bool
the property turned to false, disallows session to load data via cellular
check more here

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