Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Android): getCurrentWifiSSID return null if '<unknown ssid>' #148

Merged
merged 3 commits into from
Jan 10, 2021
Merged

fix(Android): getCurrentWifiSSID return null if '<unknown ssid>' #148

merged 3 commits into from
Jan 10, 2021

Conversation

eliaslecomte
Copy link
Collaborator

@eliaslecomte eliaslecomte commented Dec 18, 2020

Sometimes while switching network, android returns .
You aren't connected, so let's simply return an empty string.

@eliaslecomte
Copy link
Collaborator Author

Actually what happens on iOS if you are not connected? Is empty string returned or an exception?

@Rapsssito
Copy link
Collaborator

@eliaslecomte, looking at the code:

- (NSString *) getWifiSSID {
NSString *kSSID = (NSString*) kCNNetworkInfoKeySSID;
NSArray *ifs = (__bridge_transfer id)CNCopySupportedInterfaces();
for (NSString *ifnam in ifs) {
NSDictionary *info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam);
if (info[kSSID]) {
return info[kSSID];
}
}
return nil;
}

It looks like iOS returns nil when no SSID is found.

@eliaslecomte
Copy link
Collaborator Author

@eliaslecomte, looking at the code:

- (NSString *) getWifiSSID {
NSString *kSSID = (NSString*) kCNNetworkInfoKeySSID;
NSArray *ifs = (__bridge_transfer id)CNCopySupportedInterfaces();
for (NSString *ifnam in ifs) {
NSDictionary *info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam);
if (info[kSSID]) {
return info[kSSID];
}
}
return nil;
}

It looks like iOS returns nil when no SSID is found.

Thanks! I've aligned this with Android :-).

@eliaslecomte eliaslecomte self-assigned this Dec 22, 2020
@Rapsssito Rapsssito changed the title getCurrentWifiSSID - Android handle '<unknown ssid>' fix(Android): getCurrentWifiSSID return null if '<unknown ssid>' Dec 22, 2020
@Rapsssito
Copy link
Collaborator

@eliaslecomte, taking a deeper look, it looks like when get a null SSID in iOS, we reject the promise with the message "Cannot detect SSID".

if(self.solved == NO){
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse ||
[CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedAlways){
NSString *SSID = [self getWifiSSID];
if (SSID){
resolve(SSID);
return;
}
NSLog(@"RNWIFI:ERROR:Cannot detect SSID");
reject([ConnectError code:CouldNotDetectSSID], @"Cannot detect SSID", nil);

What do you think? Should we also reject in Android or change the iOS part in order to return null too?

@eliaslecomte
Copy link
Collaborator Author

@Rapsssito I've changed the Android code to also reject in this case.

@Rapsssito Rapsssito merged commit 336668a into JuanSeBestia:master Jan 10, 2021
JuanSeBestia pushed a commit that referenced this pull request Jan 10, 2021
## [4.3.6](v4.3.5...v4.3.6) (2021-01-10)

### Bug Fixes

* **Android:** getCurrentWifiSSID return null if '<unknown ssid>' ([#148](#148)) ([336668a](336668a))
@JuanSeBestia
Copy link
Owner

🎉 This PR is included in version 4.3.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants