detect hotspot enabling in iOS with private api's
Without Private APIs
You can detect active personal hotspot by enumerating network interfaces using C APIs. When hotpost is active and someone is connected to it there will be interface with bridge
prefix. On my iPhone 5 it's bridge100
. If hotspot is disabled or no one is connected to it that interfaces will not even be in the list.
C APIs will even return you IP address and subnet mask in that network.
That's what I'm using in my applications to detect active hotspot.
To get SSID you need [[UIDevice currentDevice] name]
- personal hotspot SSID always matches device name.
With Private APIs
You can obtain all the information about personal hotspot using this code:
SCDynamicStoreRef sc = SCDynamicStoreCreate(NULL, CFSTR("com.apple.wirelessmodemsettings.MISManager"), NULL, NULL);
NSDictionary* info = (__bridge_transfer NSDictionary*)SCDynamicStoreCopyValue(sc, CFSTR("com.apple.MobileInternetSharing"));
CFRelease(sc);
info
dictionary will look something like this when hotspot is active and has connections:
{
Errnum = 0;
ExternalInterfaces = (
"pdp_ip0"
);
Hosts = {
Current = 1;
Max = 5;
MoreAllowed = 1;
Type = {
AirPort = 0;
Bluetooth = 0;
Ethernet = 0;
"USB-Ethernet" = 1;
};
};
InternalInterfaces = (
bridge100
);
Reason = 0;
State = 1023;
Version = 2;
}
When hotspot is active but there are no connections:
{
Errnum = 0;
ExternalInterfaces = (
);
Hosts = {
Current = 0;
Max = 5;
MoreAllowed = 1;
Type = {
AirPort = 0;
Bluetooth = 0;
Ethernet = 0;
"USB-Ethernet" = 0;
};
};
InternalInterfaces = (
);
Reason = 0;
State = 1023;
Version = 2;
}
When hotspot is not active:
{
Errnum = 45;
ExternalInterfaces = (
);
Hosts = {
Current = 0;
Max = 5;
MoreAllowed = 1;
Type = {
AirPort = 0;
Bluetooth = 0;
Ethernet = 0;
"USB-Ethernet" = 0;
};
};
InternalInterfaces = (
);
Reason = 0;
State = 1022;
Version = 2;
}
State
key will be equal to 1023
when hotspot is active regardless of active connections. I don't know whether that value contains bit-flags or not. iOS is actually checking if value is equal to 1023
.
SCDynamicStore APIs are from public SystemConfiguration
framework but marked as not available on iOS platform. That means all the headers are there, you just need to copy definitions without __OSX_AVAILABLE_STARTING
macro.
You can even observe changes to that setting - you can specify a key which value you want to observe. Read Apple documentation for implementation details.
UPDATE
So i went into SCDynamicStore.h and changed the following
I wouldn't do that. It shouldn't cause any problems but for me changing SDK headers is not a good solution. I suggest the following. Don't include the framework headers. Make your own header where you copy all the methods you need with __OSX_AVAILABLE_STARTING
changed or removed.
Private API for Tethering on iPad
I'm not aware of a private tethering API.
If all you want to do is have your own private WIFI hotspot, and you're an iPhone developer, then you can download/build/install iProxy: https://github.com/tcurdt/iProxy/wiki/. Not quite tethering but close enough for most needs.
Detect hotspot crashed in iPhone X
There's a way to check CNCopyCurrentNetowrkInfo for current network info.
And there's hacks:
Obj-c:
CGFloat statusBarHeight = [[UIApplication sharedApplication] statusBarFrame].size.height;
Swift:
let statusBarHeight = UIApplication.shared.statusBarFrame.size.height
With Personal Hotspot enabled, it returns 40, and returns 20 otherwise.
Please note that it's not going to work for iPhone X+
Is it possible to programmatically enable hotspot mode in iPhone?
You can't create a HotSpot in code talking via an API or via a Configuration Profile
Have you looked at GameKit which does a great job of easing connecting devices transparently via Bluetooth or WiFi? Don't let the "Game" name fool you - it's a great and easy to use library.
Related Topics
Uibutton with Single Press and Long Press Events Swift
Itms-90809: Deprecated API Usage - Existing App That Use Uiwebview Are No Longer Accepted
iOS Color to Transparent in Uiimage
Enable Uialertaction of Uialertcontroller Only After Input Is Validated
Uipickerview as Inputview of Uitextfield
React-Native Loading Image Over Https Works While Http Does Not Work
Switching from Xcode3 to Xcode4 - Can't Load Programs Onto Older Ipod Touch
Font Descriptor Returns Nil in iOS 8
iOS Apns "Best-Effort" Fallback
Libz.Dylib Versus Libz.1.2.3.Dylib Versus Libz.1.2.5.Dylib
Apple Push Notification in Background Issue
Share Datas Between Two Apps with iOS 8 App Groups (Using Nsuserdefaults)
How to Remove All References for Outlet
Passing Data Between Two Viewcontrollers (Delegate) - Swift