NEHotspotConfigurationManager Can it get the WiFi list? - ios

iOS released the public API NEHotspot ConfigurationManager
Inside there is a function: getConfiguredSSIDs (completionHandler: ([String]) -> Void)
Do not know the return value of this, my Code like:
Code :
[[NEHotspotConfigurationManager sharedManager] getConfiguredSSIDsWithCompletionHandler: ^ (NSArray * array) {
            
             NSLog (# "Response:% #", array);
           
         }];
However, the value is null .. Why?
Is there any way to get nearby WiFi using NEHotspotConfigurationManager without going through NEHotspotHelper?

For security reasons your app only has access to SSIDs that your app itself has configured.
To configure a wifi network you need to enable the Hotspot Configuration entitlement in your app settings and then call:
NEHotspotConfigurationManager.shared.apply()
It's also worth noting that if the user has already manually joined the wifi network outside of your app when your app tries to join that network you will get an error stating that they are already a member and it won't show up in the ConfiguredSSIDs list, so try to support this as well.

Related

iOS - Get device's WIFI IP Address

I need to get the device IP of the WiFi interface.
According to several StackOverflow threads, we could assume that "en0" corresponds to the Wi-Fi interface name :
https://stackoverflow.com/a/30754194/12866797
However, this feels like some kind of convention, not a standard.
Is there any consistent/standard way to retrieve the WiFi interface or the device WiFi IP address, using the iOS SDK ?
It would be nice if the API is available starting from iOS 11 but I won't be picky.
My best attempt was to use NWPathMonitor (iOS 12+) and monitor network changes corresponding to WiFi interfaces (NWInterface.InterfaceType.wifi) :
- (void) MonitorWifiInterface
{
m_pathMonitor = nw_path_monitor_create_with_type(nw_interface_type_wifi);
nw_path_monitor_set_update_handler(m_pathMonitor, ^(nw_path_t _Nonnull path) {
NSLog(#"[NetInterfaceUtilies] Network path changed");
nw_path_enumerate_interfaces(path, ^ bool (nw_interface_t _Nonnull itf)
{
NSLog(#"[NetInterfaceUtilies] Name : %s , Index : %u", nw_interface_get_name(itf), nw_interface_get_index(itf));
return true; // In order to continue the enumeration
});
});
nw_path_monitor_start(m_pathMonitor);
}
But I am not happy with it for the following reasons :
NWPathMonitor is supposed to be used for monitoring network changes : I haven't managed to get network information whenever I wanted, but only when WiFi has been set on/off.
I only managed to get the network interface name. But I can combine this data with the network interfaces retrieved with getifaddrs() in order to deduce the correct interface and IP : it's a step forward ?
It's "only" available starting from iOS 12.

What devices does CBCentralManager.retrieveConnectedPeripherals() return?

I want to check which Bluetooth Devices my iPhone is connected to. In order to do that, I use CBCentralManager.retrieveConnectedPeripherals() like this:
let connectedPerphs = centralManager.retrieveConnectedPeripherals(withServices: []);
My problem is that even if my iPhone is connected to a BluetoothDongle (it explicitly says "connected" in the settings), the list that is returned by retriveConnectedPeripherals() is always empty. Am I using the method in a wrong way or can it not be used to detect a bluetooth connection such as the connection to to my dongle? If the latter is the case, how can I detect that connection?
Let me clear, centralManager.retrieveConnectedPeripherals always return empty or nil value, If you are not passing any value into serviceUUIDs
retrieveConnectedPeripherals(withServices:)
Returns a list of the peripherals (containing any of the specified
services) currently connected to the system.
serviceUUIDs:
A list of service UUIDs (represented by CBUUID objects).
Update:
Unfortunately this the long way to do it. You can create Array of CBUUID statically then you can pass it to the method. Please refer below code.
let aryUUID = ["1800","18811"]
var aryCBUUIDS = [CBUUID]()
for uuid in aryUUID{
let uuid = CBUUID(string: "1800")
aryCBUUIDS.append(uuid)
}
let connectedPerphs = centralManager.retrieveConnectedPeripherals(withServices: aryCBUUIDS)
List of available services
First, this works only with BLE devices, thus if your dongle is using a common BT you will not get it from here, but probably using EAAccessoryManager var connectedAccessories: [EAAccessory] method, but as far as I know your app must comply to MFI.
That is why is asking which service your devices are exposing as a filter.

Offer & Answer from same device iOS in WebRTC

In Normal Structure, its followed two devices are connected to each other to communicate.
Is it possible to connect same iOS Device to connect itself using WebRTC servers (turn, stun).
What I did So far.
Initialized RTCPeerConnectionFactory & setup Peer Connection
[_peerConnection offerForConstraints:constraints
completionHandler:^(RTCSessionDescription *sdp,
NSError *error) {
NSLog(#"My SDP is %#", sdp);
NSLog(#"My Error is %#", error);
remoteSDP = sdp;
[self setLocalLocalDescription:sdp];
[self setRemoteRemoteDescription:sdp];
}];
I received SDP, I set on local description of _peerConnection's setLocalDescription & _peerConnectionremote's setRemoteDescription
I prepared Answer from _peerConnectionremote, and I received SDP, which I set _peerConnectionremote's setLocalDescription & _peerConnection's setRemoteDescription.
I set Ice candidate in didGenerateIceCandidate, as
if (peerConn == _peerConnection) {
[_peerConnection addIceCandidate:candidate];
}else if (peerConn == _peerConnectionremote) {
[_peerConnectionremote addIceCandidate:candidate];
}
I receive remote media stream in
- (void)peerConnection:(RTCPeerConnection *)peerConn
didAddStream:(RTCMediaStream *)stream ,
which I set properly.
In last, It says, state as RTCIceConnectionStateConnected, but nothing happens more.
Is it possible, two open two streams at the same time from iOS and connect them via WebRTC.
If Yes, how can I separate sources
RTCMediaStream* stream1 = [_factory mediaStreamWithStreamId:#"ARDAMS"];
RTCMediaStream* stream2 = [_factoryremote mediaStreamWithStreamId:#"ARDAMS"];
----- For now its stopping first stream even.
Any suggestion or thoughts?
Following this Image as architect, which is working fine with me when one party is remote or other device. But when both parties are same device skipping SIGNALING SERVER, it fails.
Yes you can do this. Are you retaining the media streams when they get added in the peerConnection:didAddStream: callback? Are you adding the video tracks to a RTCVideoRenderer? The way you differentiate the two sources is by the peer connection associated with the stream when peerConnection:didAddStream gets called, similar to what you are doing with the ICE candidates

What makes a user discoverable to CKDiscoverAllUserIdentitiesOperation?

I am trying to discover contacts for a user with the code below (the code is in an implementation of a UITableViewController. I put breakpoints in both code blocks, and I determined that the the userIdentityDiscoveredBlock is not called while the completionBlock is called. This indicates that the operation is being run as expected, it just isn't finding any contacts.
I am running on the simulator, but I verified that the simulator has synced all my iCloud contacts (opening the Contacts app on the simulator shows all my contacts).
override func viewDidLoad() {
super.viewDidLoad()
let op = CKDiscoverAllUserIdentitiesOperation()
op.discoverAllUserIdentitiesCompletionBlock = { error -> Void in
// reload my data table
}
op.userIdentityDiscoveredBlock = { user -> Void in
if user.hasiCloudAccount {
self.iCloudUsers.append(user)
} else {
self.nonICloudUsers.append(user)
}
}
CKContainer.default().add(op)
}
So my question is this - Is there something else that has to be done in order to discover contacts? Is this a simulator issue?
I searched the documentation and other questions but I can't seem to find information on this given the operation is new to iOS 10.
There's quite a bit that must be done before CKDiscoverAllUserIdentitiesOperation will return any results.
First, each user of your app must grant permission to be looked up by email. Your app makes this request using CKContainer requestApplicationPermission.
Each user of your app must also be logged into an iCloud account. iCloud Drive must also be enabled by the user.
And lastly, for CKDiscoverAllUserIdentitiesOperation to return any users, the person must have contacts with email addresses that match other users that completed all of the previous steps.

CoreWLAN or any other public API for IOS 7

I'm looking for a way to scan available Wi-Fi access points (hotspots) from my IOS-app.
All that I need is a list of active at the moment hotspot names, where a device is able to connect to.
Like Safari shows a list of Wi-Fi hotspots when we start or activate it.
I'd like to publish the app on App Store, so I can't use any kind of Private API's (right?).
And unfortunatelly CoreWLAN.framework is unavailable for IOS (right?).
So, is it possible to achieve my target? Can I collect available access points names (SSID) some way?
There is no Public APIs at the moment that you can use to get a list of available Wi-Fi access points. As you're planning to publish on the App Store, Private APIs are not an option.
The closest thing you can achieve is getting your currently connected Wi-Fi name and details which can be achievied with CaptiveNetwork with the SystemConfiguration.framework.
+ (NSString *)currentSSID
{
NSString *ssid;
NSArray *interfaces = (__bridge_transfer id)CNCopySupportedInterfaces();
for (NSString *interfaceName in interfaces) {
NSDictionary *informations = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)interfaceName);
if (informations[#"SSID"]) {
ssid = informations[#"SSID"];
}
}
return ssid;
}

Resources