fixed ios wifi part support. retry 2.

This commit is contained in:
aria committed 2026-04-22 19:29:46 +09:00
1 parent 521c14b2fc
commit 13d06d50eb
4 files changed
+30 -5

No files matched your search

+27 -3
View File
@@ -286,6 +286,10 @@ static NSString * const BluememeDeviceKeyDefaultsKey = @"bluememe_utils_device_k
NSString *ssid = [self stringFromDictionary:options key:@"ssid"];
NSString *password = [self stringFromDictionary:options key:@"password"];
NSString *security = [[self stringFromDictionary:options key:@"security"] lowercaseString];
if (security.length == 0) {
security = password.length == 0 ? @"open" : @"wpa2";
}
BOOL isOpen = [security isEqualToString:@"open"] || [security isEqualToString:@"none"];
BOOL isWep = [security isEqualToString:@"wep"] || [self boolFromDictionary:options key:@"isWep" defaultValue:NO];
BOOL joinOnce = [self boolFromDictionary:options key:@"joinOnce" defaultValue:defaultJoinOnce];
BOOL hiddenSsid = [self boolFromDictionary:options key:@"hiddenSsid" defaultValue:NO];
@@ -295,6 +299,16 @@ static NSString * const BluememeDeviceKeyDefaultsKey = @"bluememe_utils_device_k
return;
}
if (!isOpen && password.length == 0) {
[self sendErrorForCommand:command code:@"INVALID_WIFI_OPTIONS" message:@"password is required for secured WiFi networks."];
return;
}
if (!isOpen && !isWep && (password.length < 8 || password.length > 63)) {
[self sendErrorForCommand:command code:@"INVALID_WIFI_OPTIONS" message:@"WPA/WPA2 passphrase must be 8 to 63 characters."];
return;
}
#if TARGET_OS_SIMULATOR
[self sendErrorForCommand:command
code:@"UNSUPPORTED_IOS_SIMULATOR"
@@ -304,7 +318,7 @@ static NSString * const BluememeDeviceKeyDefaultsKey = @"bluememe_utils_device_k
if (@available(iOS 11.0, *)) {
NEHotspotConfiguration *configuration = nil;
if (password.length == 0 || [security isEqualToString:@"open"]) {
if (isOpen) {
configuration = [[NEHotspotConfiguration alloc] initWithSSID:ssid];
} else {
configuration = [[NEHotspotConfiguration alloc] initWithSSID:ssid passphrase:password isWEP:isWep];
@@ -317,7 +331,14 @@ static NSString * const BluememeDeviceKeyDefaultsKey = @"bluememe_utils_device_k
[[NEHotspotConfigurationManager sharedManager] applyConfiguration:configuration completionHandler:^(NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (error != nil && error.code != NEHotspotConfigurationErrorAlreadyAssociated) {
[self sendWifiApplyErrorForCommand:command error:error];
NSDictionary *context = @{
@"ssid": ssid,
@"security": security,
@"passwordLength": @(password.length),
@"joinOnce": @(joinOnce),
@"hiddenSsid": @(hiddenSsid)
};
[self sendWifiApplyErrorForCommand:command error:error context:context];
return;
}
NSDictionary *result = @{
@@ -335,9 +356,12 @@ static NSString * const BluememeDeviceKeyDefaultsKey = @"bluememe_utils_device_k
}
}
- (void)sendWifiApplyErrorForCommand:(CDVInvokedUrlCommand *)command error:(NSError *)error
- (void)sendWifiApplyErrorForCommand:(CDVInvokedUrlCommand *)command error:(NSError *)error context:(NSDictionary *)context
{
NSMutableDictionary *details = [NSMutableDictionary dictionary];
if (context != nil) {
[details addEntriesFromDictionary:context];
}
if (error.domain.length > 0) {
details[@"nativeDomain"] = error.domain;
}