Phonegap contacts.find成功不会在第一次尝试时触发 - 在第二次尝试中取消结果

时间:2014-02-05 21:38:05

标签: cordova phonegap-plugins

我在PhoneGap 3.3.0中遇到了一个奇怪的问题(iOS,尚未在Android上测试过),当我执行contacts.find时,它没有触发成功或错误。我第二次开火它就会工作,但它会给我两次联系人条目......

// Set the options for the contacts request
            var options = new ContactFindOptions();
            options.filter = "";
            options.multiple = true;

            filter = ["displayName", "name", "phoneNumbers", "emails", "photos"];

            // Getting the contacts
            navigator.contacts.find(filter, function(contacts){
                console.log(contacts);

                // If contacts were found:
                // For each contact result...
                contacts.forEach(function(item, index){
                    // Check to make sure they have a first or last name
                    if(item.name.givenName != null || item.name.familyName != null) {
                        // If that have a first or last name:
                        // Add the persons first and/or last name to the mycontacts array
                        mycontacts.pushObject((item.name.givenName != null ? item.name.givenName+" " : "")+(item.name.familyName != null ? item.name.familyName : ""));
                    }
                });

                console.log(mycontacts);

                // Mark "gotcontacts" as being done successfully to prevent unrequired calls
                that.set("gotcontacts", true);

                that.send('loaderOff');
            }, function(error){
                console.log("couldn't get contacts");
                // If there was an error getting the contacts
                alert("Sorry, we couldn't find any contacts.");

                that.send('loaderOff');
            }, options);

我在按下按钮时触发了呼叫。

如果有人有任何想法,为什么这将是伟大的。现在我迷路了!

0 个答案:

没有答案