電話ギャップを使用してアプリケーションに取り組んでいます。後で使用するので、モバイルから連絡先にアクセスしようとしています。私は今、モバイルで連絡先を見つけるためのコードを書こうとしています。私が使用しているJSファイルは次のとおりです。
alert('Starting JS');
var TAP = ('ontouchend' in window) ? 'touchend' : 'click';
alert('I entered the function');
document.addEventListener('DOMContentLoaded', function () {
alert('I entered the second function');
x$('#friendSubmit').on(TAP, function () {
var filter = x$('#friendName')[0].value;
alert('I entered the third function');
if (!filter)
{
alert('Cant find contacts');
// no contents
return;
}
else
{
findContactByName(filter, function (contacts)
{
alert(contacts.length + ' contact(s) found matching "' +filter + '"');
}
); }
}); });
function findContactByName(name, callback) {
function onError() {
alert('Error: unable to read contacts');
};
var fields = ["displayName", "name"],
options = new ContactFindOptions();
options.filter = name;
options.multiple = true;
// find contacts
navigator.service.contacts.find(fields, callback, onError,
options);
}
どのアラートもアラートされないため、コードに何か問題があるようです (ただし、「findContactByName」関数を削除するとアラートが発生しました。
これらの機能が機能するように、何らかの種類のプラグインを追加したり、何かを更新したりする必要があるかどうか知っていますか? 私はcordovaバージョン1.6.1で作業しており、連絡先にアクセスできるようにマニフェストの権限を更新しました。では、私のコードの何が問題なのか、なぜ機能しないのか分かりますか?
どうもありがとう。