kolwit / com.kolwit.pickcontact

Another Contact Picker plugin for Cordova 3.x and PhoneGap
MIT License
5 stars 6 forks source link

Plugin not working #3

Open keniobats opened 10 years ago

keniobats commented 10 years ago

Hello, first of all, thanks for your work.

I've been trying to use your plugin with no luck. I created a new cordova project, added your plugin with "cordova plugins add com.kolwit.pickcontact"(installed succesfully), and then added your code right after the app.initialize():

window.plugins.PickContact.chooseContact(function (contactInfo) {
    setTimeout(function () { // use time-out to fix iOS alert problem
        alert(contactInfo.displayName + " " + contactInfo.emailAddress + " " + contactInfo.phoneNr );
    }, 0);
});

But nothing seems to happen.

If I try checking with "org.apache.cordova.contacts" plugin:

if (!navigator.contacts) {
        alert("Contacts API not supported", "Error");
        return;
    }

It shows the alert saying that there's no support for it.

Could you please give me a hint about this?. Thanks in advance!

Tested on Samsung S3 Mini, Android 4.4.2

kolwit commented 10 years ago

Hi @keniobats ,

the function you use to check for the api support is, i think, especially for the cordova contacts plugin. If you want to check for this plugin you should use something like:

if (!window.plugins.PickContact) {
        alert("PickContact API not supported", "Error");
        return;
    }

Another thing. I think it would be best if you trigger the plugin with some user action, such as a button. So, put the plugin call inside a function and trigger the function with the user action.

And, make sure the plugin is triggered after your app has been fully loaded.

Last, you can also trigger a function on error.

Something like this:

<script type="text/javascript">
var cordovaHasLoaded = false;

document.addEventListener("deviceready", function() {
        cordovaHasLoaded = true;
        }, false);

var successFunc = function (contactInfo) {
        alert(contactInfo.displayName + " " + contactInfo.emailAddress + " " + contactInfo.phoneNr );
};

var errorFunc = function (c,m) {
        console.log('PickContact failed: ' + c + ' - ' + m);
};

function triggerPickContact() {
        if (cordovaHasLoaded) {
                window.plugins.PickContact.chooseContact(successFunc, errorFunc);
        } else {
                alert('device is not ready');
        }
}
</script>
<input type="button" value="pick contact" onClick="triggerPickContact();" />
keniobats commented 10 years ago

Hi @kolwit,

Thanks for your support but I'm having a hard time trying to make it work.

I don't know why I'm getting a "Uncaught ReferenceError: triggerPickContact is not defined" when firing the function.

If it's not too much to ask, could you please provide me a full example of a working app 'cause I'm probably doing something wrong.

Thanks in advance!