tripflex / WifiWizard2

A Cordova plugin for managing Wifi networks (new version of WiFiWizard) - Latest is version 3+
https://www.npmjs.com/package/cordova-plugin-wifiwizard2
Apache License 2.0
123 stars 146 forks source link

min version of Android supported #65

Open Sumbersss opened 5 years ago

Sumbersss commented 5 years ago

<!--

Have you read the plugins' Code of Conduct? By creating an Issue, you are expected to comply with it, including treating everyone with respect: https://github.com/tripflex/wifiwizard2/blob/master/CODE_OF_CONDUCT.md

-->

Prerequisites

Check all boxes if you have done the following:

Issue type

Select all that apply

Description

I have a small question, what is the min version of Android supporting this plugin ? On Android 5.0 the plugin doesn't work, that means i don't have the automagic demand to activate the wifi, so my application do not launch (because it's testing at the launch on which wifi i am connected)

Steps to Reproduce

Versions

wifizard2: 3.1.0 Android: 5.0

Additional Information

tripflex commented 5 years ago

@Sumbersss i'm honestly not sure, what errors or issues are you getting? Please provide specifics so we can look into this for you

Sumbersss commented 5 years ago

I can't see the error because it's at the early launch of my application but i can show you a part of the logic. Also, can I disable the auto ask for activation of the wifi ?

Here is the code.

$ionicPlatform.ready(function () {
            try {
                if (window.cordova) {
                    function successGetSSID(ssid) {
                        if (_.includes(ssid, DISPENSER_CONFIG.SSID_NAME))
                            live.init();
                        else {
                            checkAutoLogin();
                        }
                    }
                    wifiManager.getConnectedSSID().then(successGetSSID, checkAutoLogin);
                } else {
                    checkAutoLogin();
                }
            } catch (e) {
                console.error("error occured : ", e);
            }
        });

with getConnectedSSID

var getConnectedSSID = function() {
            return ($q(function(resolve, reject) {
                if (window.cordova) {
                    if (ionic.Platform.isAndroid()) {
                        WifiWizard2.requestPermission()
                            .then(function() {
                                WifiWizard2.getConnectedSSID()
                                    .then(function(ssid) {
                                        resolve(ssid);
                                    }, function(fail) {
                                        reject(fail);
                                    });
                            }, function(fail) {
                                reject();
                            })
                    }
                    else if (ionic.Platform.isIOS()) {
                        WifiWizard2.getConnectedSSID()
                            .then(function(ssid) {
                                resolve(ssid);
                            }, function(fail) {
                                reject(fail);
                            });
                    }
                }
                else
                    reject();
            }));
        };
TheSegfault commented 5 years ago

First of all, have you ever tried to code properly ??? Wtf is this shit

Check the code after 2min of thinking like a normal human being

var getConnectedSSID = function () {
    return $q(function (resolve, reject) {
        if (!window.cordova) {
            reject();
        }

        function connectWithWizard() {
            WifiWizard2.getConnectedSSID().then(onSuccess, onReject);
        }

        function onSuccess(ssid) {
            resolve(ssid);
        }

        function onReject(fail) {
            reject(fail);
        }

        if (ionic.Platform.isAndroid()) {
            WifiWizard2.requestPermission().then(connectWithWizard, onReject);
        } else if (ionic.Platform.isIOS()) {
            connectWithWizard();
        }

    });
};

For the early launch -> chrome://inspect

astinka commented 4 years ago

Under Android versions below 6.0 your WifiWizard2.requestPermission() will not return a result (when I tried it, the promise kept being stuck on 'pending' indefinitely).

The simple reason for this is that below Android 6 there were no permission dialogues at all. You can mitigate this by only making this call after checking the Android version is 6 or above.

Not sure if this should be considered as a bug worth reporting.