Getting WIFI Signal strength in iPhone - ios

I know this is a duplicate of many similar questions.But none of them were clear they where not giving proper solutions.My question is how to get WiFi signal strength in iOS devices?. I know it has done using Private API's but I don't know how to use?. Please can anyone help me please?

For ios9+
Register your app as Hotspot helper. (forums.developer.apple.com/message/30657#30657)
#import <NetworkExtension/NetworkExtension.h>
for(NEHotspotNetwork *hotspotNetwork in [NEHotspotHelper supportedNetworkInterfaces]) {
NSString *ssid = hotspotNetwork.SSID;
NSString *bssid = hotspotNetwork.BSSID;
BOOL secure = hotspotNetwork.secure;
BOOL autoJoined = hotspotNetwork.autoJoined;
double signalStrength = hotspotNetwork.signalStrength;
}
Reference:- https://stackoverflow.com/a/32971064/988169

Apple restrict (wireless private api) to use private api to find the strenth of wifi .

Related

How to detect that haptic feedback is disabled on iOs device?

I want to to show message in my application when haptic feedback is disabled in phone settings. How to detect that haptic feedback is disabled in device settings?
It's kludgy, but might this work?
- (BOOL)isHapticFeedbackDisabled {
BOOL result = NO;
UISelectionFeedbackGenerator *feedbackGenerator = [[UISelectionFeedbackGenerator alloc] init];
[feedbackGenerator prepare];
if ([feedbackGenerator.description containsString:#"prepared=0"]) result = YES;
feedbackGenerator = nil;
return result;
}
There is no way to check Haptic Feedback is enabled/disabled but there is private int _feedbackSupportLevel in UIKit for checking if device supports it:
func logFeedbackSupported() {
let supportLevel = UIDevice.current.value(forKey: "_feedbackSupportLevel")
print(supportLevel ?? "")
}
0: Not available,
1: First generation available (< iPhone 7),
2: Second generation available.
I advise you not to use Apples private APIs because:
The API could be changed in any version without you knowing about it.
Apple is parsing your app code to find out if you're using private API so be aware. Your app could be rejected.

How to detect network state in BlackBerry 10.2

I want to detect the state of network. I found two ways to look for the internet connection in bb 10.2 but no one seems to be working:
1: It always return "QNetworkAccessManager::UnknownAccessibility"
QNetworkAccessManager* networkAccessManager = new QNetworkAccessManager(this);
networkAccessManager->networkAccessible();
2: It always return true
QNetworkConfigurationManager *manager = new QNetworkConfigurationManager();
bool res = QObject::connect(manager,
SIGNAL(onlineStateChanged(bool)),
this,
SLOT(onOnlineStateChanged(bool)));
Q_ASSERT(res);
Could anybody help me on this?
A solution is to use QNetworkConfigurationManager::isOnline().
QNetworkConfigurationManager *manager = new QNetworkConfigurationManager();
Q_ASSERT(manager->isOnline());

How do I know if cellular access for my iOS app is disabled?

I have an iOS app that makes some small network requests on app launch (resource updates, etc). If the user turns off cellular access for the app in iOS Settings, they get a prompt from iOS about network usage every time they launch. Is there a way to know programmatically that cellular data for this app has been disabled, so that I can disable the requests at startup?
So I found this on the apple dev forums from an Apple engineer (https://devforums.apple.com/message/1059332#1059332).
Another developer wrote in to DTS and thus I had a chance to
investigate this in depth. Alas, the news is much as I expected:
there is no supported way to detect that your app is in this state.
Nor is there a way to make a "no user interaction" network connection,
that is, request that the connection fail rather than present UI like
this. If these limitations are causing problems for your app, I
encourage you to file a bug describing your specific requirements.
https://developer.apple.com/bug-reporting/
So it looks like it is not possible to detect if cellular data for your app has been turned off.
Edit
I filed a radar for this requesting that it be added. I just got this notification in my radar
We believe this issue has been addressed in the latest iOS 9 beta.
I looked through the API diffs, but so far I can't find the new API.
As of iOS9, the capability to check the setting to enable/disable use of cellular data for your app (Settings/Cellular/AppName) is available using Apple's CTCellularData class. The following code will set cellularDataRestrictedState when it is run initially and then set it and log whenever it changes:
import CoreTelephony
var cellularDataRestrictedState = CTCellularDataRestrictedState.restrictedStateUnknown
let cellState = CTCellularData.init()
cellState.cellularDataRestrictionDidUpdateNotifier = { (dataRestrictedState) in
if cellularDataRestrictedState != .restrictedStateUnknown { // State has changed - log to console
print("cellularDataRestrictedState: " + "\(dataRestrictedState == .restrictedStateUnknown ? "unknown" : dataRestrictedState == .restricted ? "restricted" : "not restricted")")
}
cellularDataRestrictedState = dataRestrictedState
}
Unfortunately (as of iOS11) this seems to check only the state of the app's switch - if your app's switch is set to enabled and the user switches the Cellular Data master switch to disabled, this API will return the app's state as being "not restricted".
Just wanted to add an Objective C version of the above Swift code for future travellers.
- (void)monitorCanUseCellularData {
if (GCIsiOS9) {
CTCellularData *cellularData = [[CTCellularData alloc] init];
NSLog(#"%ld", cellularData.restrictedState);
// 0, kCTCellularDataRestrictedStateUnknown
[cellularData setCellularDataRestrictionDidUpdateNotifier:^(CTCellularDataRestrictedState state) {
NSLog(#"%ld", state);
self.canUseCellularData = cellularData.restrictedState ==2?true:false;
}];
}
}
I have found that the CTCellularData class needs some time to get to the correct value. In my implementation I call the didUpdateNotifier very early after appDidFinishLaunching. By the time my networking call are returning with errors I definitely have a correct value for the restricted state.
class CellularRestriction: NSObject {
private static var cellularData = CTCellularData()
private static var currentState = CTCellularDataRestrictedState.restrictedStateUnknown
static var isRestricted: Bool {
currentState = cellularData.restrictedState
return currentState == .restricted
}
static func prepare() {
if currentState == .restrictedStateUnknown {
cellularData.cellularDataRestrictionDidUpdateNotifier = { state in
currentState = cellularData.restrictedState // This value may be inconsistent, however the next read of isRestricted should be correct.
}
}
}
}
You can detect if cellular data disabled using NWPathMonitor class. (https://developer.apple.com/documentation/network/nwpathmonitor)
let cellMonitor = NWPathMonitor(requiredInterfaceType: .cellular)
cellMonitor.pathUpdateHandler = { path in
self.isCellConnected = path.status == .satisfied
}
Adding to dirkgroten's answer, you can use the Apple Reachability class, found here:
https://developer.apple.com/Library/ios/samplecode/Reachability/Introduction/Intro.html
It uses SCNetworkReachability, and is very straight forward to use, it will detect connectivity via Cell and WiFi as you will need to check both at start up.
There are lots of frameworks out there that will give you the status of your network connectivity, and of course you can roll your own. I've found AFNetworking to be one of the best. It has a singleton class called AFNetworkReachabilityManager that abstracts some of the complexities for you. Specifically you'll want to look at the two boolean properties:
reachableViaWWAN
reachableViaWiFi
There is also a reachability changed status block that you can set:
– setReachabilityStatusChangeBlock:
AFNetworking Github
AFNetworkReachabilityManager

iOS Get Link Speed (Router Speed Test)

I want to test speed of connected router(wifi modem) from iOS app.
I've found something here Get link speed programmatically? but could not found sockios.h and ethtool.h
Is it possible to port this code to Objective-C or is there another way?
--
Sorry for the missing info and my poor english.
I want to test link speed (tx rate) between ios device and connected wifi modem.
There was a property named txRate in CWInterface class. I want to get that data in Cocoa Touch.
/*!
* #property
* #abstract Current transmit rate (Mbps) of the CoreWLAN interface.
* #discussion Dynamically queries the interface for the current transmit rate.
*/
#property(readonly) NSNumber *txRate NS_DEPRECATED_MAC(10_6, 10_7);
Finally I've found the solution.
#include <ifaddrs.h>
#include <net/if.h>
+ (double)getRouterLinkSpeed
{
BOOL success;
struct ifaddrs *addrs;
const struct ifaddrs *cursor;
const struct if_data *networkStatisc;
double linkSpeed = 0;
NSString *name = [[NSString alloc] init];
success = getifaddrs(&addrs) == 0;
if (success)
{
cursor = addrs;
while (cursor != NULL)
{
name=[NSString stringWithFormat:#"%s",cursor->ifa_name];
if (cursor->ifa_addr->sa_family == AF_LINK)
{
if ([name hasPrefix:#"en"])
{
networkStatisc = (const struct if_data *) cursor->ifa_data;
linkSpeed = networkStatisc->ifi_baudrate;
}
}
cursor = cursor->ifa_next;
}
freeifaddrs(addrs);
}
return linkSpeed;
}
You can use NSURLConnection to connect to your test server and download a preset file of something like 1 MB. Use the NSURLConnection delegate -connection:didReceiveData: and -connectionDidFinishLoading:to track the download 'so far' and compute the download speed from that.
There is currently no official (or Apple approved) way to get LinkSpeed on iOS. There were loop holes in the past which were closed unfortunately.
The most similar metric you can use to estimate LinkSpeed is measure wifi speed by sending UDP packets on the local network and measuring their sending rate. This is called IP packet sending bit rate and is defined in this ITU standard https://www.itu.int/rec/T-REC-Y.1540/en
The iOS implementation of that wifi speed measurement is in our iOS SDK which you can find here:
https://github.com/speedchecker/speedchecker-sdk-ios
This implementation is the closest you can get to estimate router wifi speed without actually placing any payload files on the router itself.

How to get IMEI on iPhone?

I want to get IMEI on iPhone. I try to use the following code:
#import "Message/NetworkController.h"
NetworkController *ntc=[[NetworkController sharedInstance] autorelease];
NSString *imeistring = [ntc IMEI];
But NetworkController is not found.
I also find that I can get uniqueIdentifier using:
UIDevice *myDevice = [UIDevice currentDevice];
NSString *identifier = myDevice.uniqueIdentifier;
But this cannot help me to get IMEI.
How to get IMEI on iPhone?
You can't get IMEI on iPhone anymore. You may have to use UDID instead. See other answers.
In the past, you could use the header file "Message/NetworkController.h" posted on ericasadun.com.
http://ericasadun.com/iPhoneDocs300/_network_controller_8h-source.html (It's been removed now)
You would add the NetworkController.h file and the private framework "Message.framework" to your project, then import that header file to use the original method I found to get the imei number:
NetworkController *ntc = [NetworkController sharedInstance];
NSString *imeistring = [ntc IMEI];
That hack doesn't work anymore. App will be rejected by Apple.
You can't find the IMEI programmatically on the iPhone.
There is no official way to get it, but in Apples private framework CoreTelephony.framework there is a method CTGetIMEI that might help you.
I'm sure there are reasons you can't do this easily. Auto-unlocker app? I don't think so. I'm sure Apple and AT&T wouldn't like it too much either.
*#06# is the way to get it manually.
I made a search only here in stackoverflow and the conclusion is that Apple dont allow anymore to find phone EMEI after iOS 6.
You can identify a device using UDID.
I found my answer here https://stackoverflow.com/a/19927376/2283308
add a head file "CoreTelephony.h" to your project
CoreTelephony.h
struct CTServerConnection
{
int a;
int b;
CFMachPortRef myport;
int c;
int d;
int e;
int f;
int g;
int h;
int i;
};
struct CTResult
{
int flag;
int a;
};
struct CTServerConnection * _CTServerConnectionCreate(CFAllocatorRef, void *, int *);
void _CTServerConnectionCopyMobileIdentity(struct CTResult *, struct CTServerConnection *, NSString **);
add the following code to your class
#import "CoreTelephony.h"
struct CTServerConnection *sc=NULL;
struct CTResult result;
void callback() { }
now, you can get imei easily
NSString *imei;
_CTServerConnectionCopyMobileIdentity(&result, sc, &imei);
https://www.telesign.com/products/phone-id
There is an SDK by a company called TeleSign that can get a device's IMEI number (in addition to a list of other things such as carrier, the home address of the device's owner, etc.). Some of the biggest apps in the store use this provider (like Tinder and Evernote). I don't work for the company or ever have, or ever want to, and I've never used any of their products. I also don't know if Apple would reject this API usage. But if you want a Swift/Objecive-C interface for getting an IMEI number, this is one.

Resources