From 0504d4058a6ca314a6d43d4de06771b880e31af0 Mon Sep 17 00:00:00 2001 From: aria Date: Thu, 23 Apr 2026 10:59:57 +0900 Subject: [PATCH] fixed ios wifi part support. retry 5. --- README.md | 5 +-- package.json | 2 +- plugin.xml | 4 ++- src/ios/CDVBluememeUtils.m | 63 +++++++++++++++++++++----------------- 4 files changed, 42 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 6a167f3..5919779 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ WiFi options: - `ssid`:必填 - `password`:开放网络可省略 - `security`:`open`、`wep`、`wpa2`、`wpa3`,默认按是否存在 password 推断为 `open` 或 `wpa2` -- `hiddenSsid`:可选;Android 支持隐藏 SSID;iOS 13+ 会设置 `NEHotspotConfiguration.hidden` +- `hiddenSsid`:可选;Android 支持隐藏 SSID;iOS 15+ 会设置 `NEHotspotConfiguration.hidden` - `bssid`:可选,仅 Android 10+ 临时连接使用 - `joinOnce`:可选,仅 iOS;`connectWifi` 默认 `true`,`saveWifi` 默认 `false` @@ -210,7 +210,8 @@ Android WiFi: iOS WiFi: -- 使用 `NEHotspotConfiguration`。 +- 使用 `NEHotspotConfiguration`,当前插件 WiFi 功能要求 iOS 15+。 +- 插件将 iOS deployment target 设置为 `15.0`;如果宿主 App 或构建平台覆盖该值,需要在宿主配置中同步设置 iOS 最低版本为 15.0 或更高。 - 插件会向 Cordova iOS entitlements 写入 `com.apple.developer.networking.HotspotConfiguration`,但仍必须在 Apple Developer App ID 中开启 `Hotspot Configuration` capability,并使用包含该 capability 的 provisioning profile 重新构建。 - 如果 iOS 返回 `NEHotspotConfigurationErrorDomain` code `8` / `internal error`,优先检查 App ID、entitlements、provisioning profile 是否都包含 `Hotspot Configuration`,并确认是在真机前台运行,不是在模拟器中测试。 - iOS 的 `NEHotspotConfiguration` password initializer 公开支持 WEP/WPA/WPA2 Personal。WPA2/WPA3 mixed 通常应先按 `security: "wpa2"` 测试;如果 WPA2-only 可用但 mixed 不可用,需要调整热点兼容性配置或改用配置描述文件/MDM 流程。 diff --git a/package.json b/package.json index ca9bb25..a00d3f7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bluememe-utils", - "version": "0.1.4", + "version": "0.1.5", "description": "Cordova utilities for WiFi, Firebase Cloud Messaging, and biometric unlock for OutSystems 11 apps.", "license": "MIT", "files": [ diff --git a/plugin.xml b/plugin.xml index ab5b339..106a15c 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="0.1.5"> bluememe-utils Cordova utilities for WiFi, Firebase Cloud Messaging, and biometric unlock. MIT @@ -72,6 +72,8 @@ + + diff --git a/src/ios/CDVBluememeUtils.m b/src/ios/CDVBluememeUtils.m index c6395d4..4451e39 100644 --- a/src/ios/CDVBluememeUtils.m +++ b/src/ios/CDVBluememeUtils.m @@ -75,11 +75,11 @@ static NSString * const BluememeDeviceKeyDefaultsKey = @"bluememe_utils_device_k return; } - if (@available(iOS 11.0, *)) { + if (@available(iOS 15.0, *)) { [[NEHotspotConfigurationManager sharedManager] removeConfigurationForSSID:ssid]; [self sendSuccessForCommand:command dictionary:@{@"ssid": ssid, @"removed": @YES}]; } else { - [self sendErrorForCommand:command code:@"UNSUPPORTED_IOS_VERSION" message:@"WiFi configuration requires iOS 11 or newer."]; + [self sendErrorForCommand:command code:@"UNSUPPORTED_IOS_VERSION" message:@"WiFi configuration requires iOS 15 or newer."]; } } @@ -316,43 +316,50 @@ static NSString * const BluememeDeviceKeyDefaultsKey = @"bluememe_utils_device_k return; #endif - if (@available(iOS 11.0, *)) { + if (@available(iOS 15.0, *)) { NEHotspotConfiguration *configuration = nil; if (isOpen) { configuration = [[NEHotspotConfiguration alloc] initWithSSID:ssid]; } else { configuration = [[NEHotspotConfiguration alloc] initWithSSID:ssid passphrase:password isWEP:isWep]; } - if (@available(iOS 13.0, *)) { - configuration.hidden = hiddenSsid; - } + configuration.hidden = hiddenSsid; configuration.joinOnce = joinOnce; - [[NEHotspotConfigurationManager sharedManager] applyConfiguration:configuration completionHandler:^(NSError *error) { - dispatch_async(dispatch_get_main_queue(), ^{ - if (error != nil && error.code != NEHotspotConfigurationErrorAlreadyAssociated) { - NSDictionary *context = @{ + void (^applyConfiguration)(void) = ^{ + [[NEHotspotConfigurationManager sharedManager] applyConfiguration:configuration completionHandler:^(NSError *error) { + dispatch_async(dispatch_get_main_queue(), ^{ + if (error != nil && error.code != NEHotspotConfigurationErrorAlreadyAssociated) { + NSDictionary *context = @{ + @"ssid": ssid, + @"security": security, + @"passwordLength": @(password.length), + @"joinOnce": @(joinOnce), + @"hiddenSsid": @(hiddenSsid), + @"minimumIos": @"15.0" + }; + [self sendWifiApplyErrorForCommand:command error:error context:context]; + return; + } + NSDictionary *result = @{ @"ssid": ssid, - @"security": security, - @"passwordLength": @(password.length), - @"joinOnce": @(joinOnce), - @"hiddenSsid": @(hiddenSsid) + @"platformMode": @"hotspotConfiguration", + @"connected": @YES, + @"saved": @(!joinOnce), + @"alreadyAssociated": @(error != nil && error.code == NEHotspotConfigurationErrorAlreadyAssociated) }; - [self sendWifiApplyErrorForCommand:command error:error context:context]; - return; - } - NSDictionary *result = @{ - @"ssid": ssid, - @"platformMode": @"hotspotConfiguration", - @"connected": @YES, - @"saved": @(!joinOnce), - @"alreadyAssociated": @(error != nil && error.code == NEHotspotConfigurationErrorAlreadyAssociated) - }; - [self sendSuccessForCommand:command dictionary:result]; - }); - }]; + [self sendSuccessForCommand:command dictionary:result]; + }); + }]; + }; + + if ([NSThread isMainThread]) { + applyConfiguration(); + } else { + dispatch_async(dispatch_get_main_queue(), applyConfiguration); + } } else { - [self sendErrorForCommand:command code:@"UNSUPPORTED_IOS_VERSION" message:@"WiFi configuration requires iOS 11 or newer."]; + [self sendErrorForCommand:command code:@"UNSUPPORTED_IOS_VERSION" message:@"WiFi configuration requires iOS 15 or newer."]; } }