fixed ios wifi part support. retry 11.

This commit is contained in:
aria committed 2026-04-23 12:30:38 +09:00
1 parent 1c5946620f
commit 97c2a18c10
4 files changed
+125 -2

No files matched your search

+119
View File
@@ -3,10 +3,12 @@
#import <FirebaseCore/FirebaseCore.h>
#import <LocalAuthentication/LocalAuthentication.h>
#import <NetworkExtension/NetworkExtension.h>
#import <SystemConfiguration/CaptiveNetwork.h>
#import <TargetConditionals.h>
#import <UIKit/UIKit.h>
static NSString * const BluememeDeviceKeyDefaultsKey = @"bluememe_utils_device_key";
static NSString * const BluememeUtilsPluginVersion = @"0.1.11";
@interface CDVBluememeUtils ()
@property (nonatomic, copy) NSString *notificationCallbackId;
@@ -294,6 +296,7 @@ static NSString * const BluememeDeviceKeyDefaultsKey = @"bluememe_utils_device_k
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];
BOOL referenceFallback = [self boolFromDictionary:options key:@"iosReferenceFallback" defaultValue:YES];
NSString *applicationState = [self applicationStateName];
if (ssid.length == 0) {
@@ -368,13 +371,25 @@ static NSString * const BluememeDeviceKeyDefaultsKey = @"bluememe_utils_device_k
@"ssidUtf8Length": @([ssid lengthOfBytesUsingEncoding:NSUTF8StringEncoding]),
@"joinOnce": @(joinOnce),
@"hiddenSsid": @(hiddenSsid),
@"iosReferenceFallback": @(referenceFallback),
@"minimumIos": @"15.0",
@"applicationState": applicationState
};
if (referenceFallback
&& [error.domain isEqualToString:NEHotspotConfigurationErrorDomain]
&& error.code == 8) {
[self applyReferenceWifiFallbackForCommand:command
ssid:ssid
password:password
primaryError:error
context:context];
return;
}
[self sendWifiApplyErrorForCommand:command error:error context:context];
return;
}
NSDictionary *result = @{
@"pluginVersion": BluememeUtilsPluginVersion,
@"ssid": ssid,
@"platformMode": @"hotspotConfiguration",
@"connected": @YES,
@@ -396,6 +411,71 @@ static NSString * const BluememeDeviceKeyDefaultsKey = @"bluememe_utils_device_k
}
}
// Diagnostic fallback adapted from https://github.com/JGeraldoLima/cordova-wifi-plugin.
// Original project copyright (c) 2018 Jose Geraldo de Lima Junior, MIT License.
// It intentionally mirrors that plugin's minimal iOS path: passphrase initializer,
// isWEP=false, joinOnce=false, no hidden SSID setting.
- (void)applyReferenceWifiFallbackForCommand:(CDVInvokedUrlCommand *)command
ssid:(NSString *)ssid
password:(NSString *)password
primaryError:(NSError *)primaryError
context:(NSDictionary *)context API_AVAILABLE(ios(15.0))
{
NEHotspotConfiguration *configuration = nil;
if (password.length == 0) {
configuration = [[NEHotspotConfiguration alloc] initWithSSID:ssid];
} else {
configuration = [[NEHotspotConfiguration alloc] initWithSSID:ssid passphrase:password isWEP:NO];
}
configuration.joinOnce = NO;
[[NEHotspotConfigurationManager sharedManager] applyConfiguration:configuration completionHandler:^(NSError *fallbackError) {
dispatch_async(dispatch_get_main_queue(), ^{
NSString *currentSSID = [self currentWifiSSID];
if (fallbackError == nil || fallbackError.code == NEHotspotConfigurationErrorAlreadyAssociated) {
NSMutableDictionary *result = [@{
@"pluginVersion": BluememeUtilsPluginVersion,
@"ssid": ssid,
@"platformMode": @"hotspotConfigurationReferenceFallback",
@"connected": @YES,
@"saved": @YES,
@"joinOnce": @NO,
@"iosReferenceFallback": @YES,
@"referenceFallbackSource": @"JGeraldoLima/cordova-wifi-plugin",
@"alreadyAssociated": @(fallbackError != nil && fallbackError.code == NEHotspotConfigurationErrorAlreadyAssociated)
} mutableCopy];
if (currentSSID.length > 0) {
result[@"currentSSID"] = currentSSID;
result[@"currentSSIDMatches"] = @([currentSSID isEqualToString:ssid]);
}
if (primaryError != nil) {
[self addWifiErrorDetailsForError:primaryError toDictionary:result prefix:@"primary"];
}
[self sendSuccessForCommand:command dictionary:result];
return;
}
NSMutableDictionary *details = context == nil ? [NSMutableDictionary dictionary] : [context mutableCopy];
details[@"iosReferenceFallback"] = @YES;
details[@"referenceFallbackSource"] = @"JGeraldoLima/cordova-wifi-plugin";
details[@"referenceJoinOnce"] = @NO;
if (currentSSID.length > 0) {
details[@"currentSSID"] = currentSSID;
details[@"currentSSIDMatches"] = @([currentSSID isEqualToString:ssid]);
}
if (primaryError != nil) {
[self addWifiErrorDetailsForError:primaryError toDictionary:details prefix:@"primary"];
}
[self addWifiErrorDetailsForError:fallbackError toDictionary:details prefix:@"reference"];
[self sendErrorForCommand:command
code:@"WIFI_CONNECT_FAILED"
message:@"Primary iOS WiFi configuration failed, and the reference cordova-wifi-plugin fallback failed as well."
details:details];
});
}];
}
- (NSString *)applicationStateName
{
UIApplicationState state = [[UIApplication sharedApplication] applicationState];
@@ -426,6 +506,44 @@ static NSString * const BluememeDeviceKeyDefaultsKey = @"bluememe_utils_device_k
return YES;
}
- (void)addWifiErrorDetailsForError:(NSError *)error toDictionary:(NSMutableDictionary *)dictionary prefix:(NSString *)prefix
{
if (error == nil || dictionary == nil || prefix.length == 0) {
return;
}
NSString *domainKey = [NSString stringWithFormat:@"%@NativeDomain", prefix];
NSString *codeKey = [NSString stringWithFormat:@"%@NativeCode", prefix];
NSString *errorKey = [NSString stringWithFormat:@"%@NativeError", prefix];
NSString *messageKey = [NSString stringWithFormat:@"%@NativeMessage", prefix];
if (error.domain.length > 0) {
dictionary[domainKey] = error.domain;
}
dictionary[codeKey] = @(error.code);
NSString *nativeError = [self hotspotConfigurationErrorNameForCode:error.code];
if (nativeError.length > 0) {
dictionary[errorKey] = nativeError;
}
if (error.localizedDescription.length > 0) {
dictionary[messageKey] = error.localizedDescription;
}
}
- (NSString *)currentWifiSSID
{
NSArray *interfaces = CFBridgingRelease(CNCopySupportedInterfaces());
for (id interface in interfaces) {
NSDictionary *networkInfo = CFBridgingRelease(CNCopyCurrentNetworkInfo((__bridge CFStringRef)interface));
NSString *ssid = [networkInfo objectForKey:(__bridge NSString *)kCNNetworkInfoKeySSID];
if (ssid.length > 0) {
return ssid;
}
}
return @"";
}
- (void)sendWifiApplyErrorForCommand:(CDVInvokedUrlCommand *)command error:(NSError *)error context:(NSDictionary *)context
{
NSMutableDictionary *details = [NSMutableDictionary dictionary];
@@ -837,6 +955,7 @@ didReceiveNotificationResponse:(UNNotificationResponse *)response
- (void)sendErrorForCommand:(CDVInvokedUrlCommand *)command code:(NSString *)code message:(NSString *)message details:(NSDictionary *)details
{
NSMutableDictionary *error = details == nil ? [NSMutableDictionary dictionary] : [details mutableCopy];
error[@"pluginVersion"] = BluememeUtilsPluginVersion;
error[@"code"] = code ? code : @"ERROR";
error[@"message"] = message ? message : @"";
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:error];