fixed ios wifi part support. retry 4.
This commit is contained in:
1 parent
f499351b21
commit
87ba9a928b
4 files changed
+36
-118
No files matched your search
+34
-114
@@ -282,13 +282,6 @@ static NSString * const BluememeDeviceKeyDefaultsKey = @"bluememe_utils_device_k
|
||||
|
||||
- (void)applyWifiCommand:(CDVInvokedUrlCommand *)command defaultJoinOnce:(BOOL)defaultJoinOnce
|
||||
{
|
||||
if (![NSThread isMainThread]) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self applyWifiCommand:command defaultJoinOnce:defaultJoinOnce];
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
NSDictionary *options = [self firstDictionaryArgument:command];
|
||||
NSString *ssid = [self stringFromDictionary:options key:@"ssid"];
|
||||
NSString *password = [self stringFromDictionary:options key:@"password"];
|
||||
@@ -300,7 +293,6 @@ 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 resetExisting = [self boolFromDictionary:options key:@"resetExisting" defaultValue:YES];
|
||||
|
||||
if (ssid.length == 0) {
|
||||
[self sendErrorForCommand:command code:@"INVALID_WIFI_OPTIONS" message:@"ssid is required."];
|
||||
@@ -325,117 +317,45 @@ static NSString * const BluememeDeviceKeyDefaultsKey = @"bluememe_utils_device_k
|
||||
#endif
|
||||
|
||||
if (@available(iOS 11.0, *)) {
|
||||
NSDictionary *context = @{
|
||||
@"ssid": ssid,
|
||||
@"security": security,
|
||||
@"passwordLength": @(password.length),
|
||||
@"joinOnce": @(joinOnce),
|
||||
@"hiddenSsid": @(hiddenSsid),
|
||||
@"resetExisting": @(resetExisting)
|
||||
};
|
||||
[self prepareAndApplyWifiConfigurationForCommand:command
|
||||
ssid:ssid
|
||||
password:password
|
||||
isOpen:isOpen
|
||||
isWep:isWep
|
||||
joinOnce:joinOnce
|
||||
hiddenSsid:hiddenSsid
|
||||
resetExisting:resetExisting
|
||||
context:context];
|
||||
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.joinOnce = joinOnce;
|
||||
|
||||
[[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)
|
||||
};
|
||||
[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];
|
||||
});
|
||||
}];
|
||||
} else {
|
||||
[self sendErrorForCommand:command code:@"UNSUPPORTED_IOS_VERSION" message:@"WiFi configuration requires iOS 11 or newer."];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)prepareAndApplyWifiConfigurationForCommand:(CDVInvokedUrlCommand *)command
|
||||
ssid:(NSString *)ssid
|
||||
password:(NSString *)password
|
||||
isOpen:(BOOL)isOpen
|
||||
isWep:(BOOL)isWep
|
||||
joinOnce:(BOOL)joinOnce
|
||||
hiddenSsid:(BOOL)hiddenSsid
|
||||
resetExisting:(BOOL)resetExisting
|
||||
context:(NSDictionary *)context API_AVAILABLE(ios(11.0))
|
||||
{
|
||||
NEHotspotConfigurationManager *manager = [NEHotspotConfigurationManager sharedManager];
|
||||
if (!resetExisting) {
|
||||
[self applyWifiConfigurationForCommand:command
|
||||
manager:manager
|
||||
ssid:ssid
|
||||
password:password
|
||||
isOpen:isOpen
|
||||
isWep:isWep
|
||||
joinOnce:joinOnce
|
||||
hiddenSsid:hiddenSsid
|
||||
context:context];
|
||||
return;
|
||||
}
|
||||
|
||||
[manager getConfiguredSSIDsWithCompletionHandler:^(NSArray<NSString *> *configuredSSIDs) {
|
||||
BOOL configuredByApp = [configuredSSIDs containsObject:ssid];
|
||||
NSMutableDictionary *updatedContext = [context mutableCopy];
|
||||
updatedContext[@"configuredByApp"] = @(configuredByApp);
|
||||
|
||||
void (^apply)(void) = ^{
|
||||
[self applyWifiConfigurationForCommand:command
|
||||
manager:manager
|
||||
ssid:ssid
|
||||
password:password
|
||||
isOpen:isOpen
|
||||
isWep:isWep
|
||||
joinOnce:joinOnce
|
||||
hiddenSsid:hiddenSsid
|
||||
context:updatedContext];
|
||||
};
|
||||
|
||||
if (configuredByApp) {
|
||||
[manager removeConfigurationForSSID:ssid];
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(500 * NSEC_PER_MSEC)), dispatch_get_main_queue(), apply);
|
||||
} else {
|
||||
dispatch_async(dispatch_get_main_queue(), apply);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)applyWifiConfigurationForCommand:(CDVInvokedUrlCommand *)command
|
||||
manager:(NEHotspotConfigurationManager *)manager
|
||||
ssid:(NSString *)ssid
|
||||
password:(NSString *)password
|
||||
isOpen:(BOOL)isOpen
|
||||
isWep:(BOOL)isWep
|
||||
joinOnce:(BOOL)joinOnce
|
||||
hiddenSsid:(BOOL)hiddenSsid
|
||||
context:(NSDictionary *)context API_AVAILABLE(ios(11.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.joinOnce = joinOnce;
|
||||
|
||||
[manager applyConfiguration:configuration completionHandler:^(NSError *error) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (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];
|
||||
});
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)sendWifiApplyErrorForCommand:(CDVInvokedUrlCommand *)command error:(NSError *)error context:(NSDictionary *)context
|
||||
{
|
||||
NSMutableDictionary *details = [NSMutableDictionary dictionary];
|
||||
|
||||
Reference in new issue
Block a user