From 94dc9d0fdf08bc147eb0812b900968b3fdf7d65b Mon Sep 17 00:00:00 2001 From: Myles McNamara Date: Tue, 28 Aug 2018 20:50:57 -0400 Subject: [PATCH] add handling in JS for iOS to connect to open network #30 --- www/WifiWizard2.js | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/www/WifiWizard2.js b/www/WifiWizard2.js index 4c76096..c001da5 100644 --- a/www/WifiWizard2.js +++ b/www/WifiWizard2.js @@ -15,27 +15,43 @@ var WifiWizard2 = { - iOSConnectNetwork: function (ssid, ssidPassword) { + /** + * Connect to network on iOS device + * @param ssid + * @param ssidPassword Password if connecting to WPA/WPA2 network (omit or use false to connect to open network) + * @returns {Promise} + */ + iOSConnectNetwork: function (ssid, ssidPassword) { return new Promise(function (resolve, reject) { + if( ssidPassword === undefined || ! ssidPassword || ssidPassword.length < 1 ){ + // iOS connect open network + cordova.exec(resolve, reject, "WifiWizard2", "iOSConnectOpenNetwork", [{ "Ssid": ssid }]); - if( ssidPassword !== undefined && ssidPassword.length > 0 && ssidPassword.length < 8 ){ + } else if( ssidPassword !== undefined && ssidPassword.length > 0 && ssidPassword.length < 8 ){ + // iOS pass length does not meet requirements (min 8 chars for WPA/WPA2) reject("WPA/WPA2 password length must be at least 8 characters in length!"); - return; - } - cordova.exec(resolve, reject, "WifiWizard2", "iOSConnectNetwork", [ + } else { + // iOS connect to WPA/WPA2 network + cordova.exec(resolve, reject, "WifiWizard2", "iOSConnectNetwork", [ { - "Ssid": ssid, - "Password": ssidPassword + "Ssid": ssid, + "Password": ssidPassword }] - ); + ); + } }); }, - iOSDisconnectNetwork: function (ssid) { + /** + * Disconnect from SSID on iOS device + * @param ssid + * @returns {Promise} + */ + iOSDisconnectNetwork: function (ssid) { return new Promise(function (resolve, reject) { cordova.exec(resolve, reject, "WifiWizard2", "iOSDisconnectNetwork", [