cordova插件- Contacts

小編:管理員 532閱讀 2022.09.13

  • 添加插件

$cordova plugin add cordova-plugin-contacts

圖 8出現如上則添加成功

  • 插件的使用
  • Methods
  • navigator.contacts.create
  • navigator.contacts.find
  • navigator.contacts.pickContact
  • Example

function openContacts () {

    navigator.contacts.pickContact(function (contact) {

        console.log('the follow contact has been selected' +JSON.stringify(contact));

    },function (err) {
        console.log('error' +err);
    })

}
復制

選擇之后返回的是一串json數據

{
復制
"id": 3,
復制
"rawId": null,
復制
"displayName": null,
復制
"name": {
復制
"givenName": "John",
復制
"honorificSuffix": null,
復制
"formatted": "John Appleseed",
復制
"middleName": null,
復制
"familyName": "Appleseed",
復制
"honorificPrefix": null
復制
},
復制
"nickname": null,
復制
"phoneNumbers": [
復制
{
復制
"value": "888-555-5512",
復制
"pref": false,
復制
"id": 0,
復制
"type": "mobile"
復制
},
復制
{
復制
"value": "888-555-1212",
復制
"pref": false,
復制
"id": 1,
復制
"type": "home"
復制
}
復制
],
復制
"emails": [
復制
{
復制
"value": "John-Appleseed@mac.com",
復制
"pref": false,
復制
"id": 0,
復制
"type": "work"
復制
}
復制
],
復制
"addresses": [
復制
{
復制
"pref": "false",
復制
"locality": "Atlanta",
復制
"region": "GA",
復制
"id": 0,
復制
"postalCode": "30303",
復制
"country": "USA",
復制
"type": "work",
復制
"streetAddress": "3494 Kuhl Avenue"
復制
},
復制
{
復制
"pref": "false",
復制
"locality": "Atlanta",
復制
"region": "GA",
復制
"id": 1,
復制
"postalCode": "30303",
復制
"country": "USA",
復制
"type": "home",
復制
"streetAddress": "1234 Laurel Street"
復制
}
復制
],
復制
"ims": null,
復制
"organizations": null,
復制
"birthday": "1980-06-22T12:00:00.000Z",
復制
"note": "College roommate",
復制
"photos": null,
復制
"categories": null,
復制
"urls": null
復制
}
復制

具體字段的含義參見:http://cordova.apache.org/docs/en/latest/reference/cordova-plugin-contacts/index.html



function createContact () {

    var myContact = navigator.contacts.create({"displayName":"test user"});

    myContact.save(function (contact) {

        console.log('the contact has created' +json.stringify(contact));

    },function (err) {

        console.log('error' +err);
    });

}
復制


function findContct () {

    function onSuccess(contact) {

        alert(' 找到=' +contact.length +'個聯系人');
    }

    function onError(error) {

        alert('error'+error);

    }
    var  options = new ContactFindOptions();
    options.filter = "test user";
    options.multiple = true;
    options.desiredFields = [navigator.contacts.fieldType.id];
    options.hasPhoneNumber = false;

    var  fields = [navigator.contacts.fieldType.displayName,navigator.contacts.fieldType.name];
    navigator.contacts.find(fields,onSuccess,onError,options);

}
復制
關聯標簽:
亚洲国产欧美图片,亚洲aⅴ在线av,日韩亚洲综合图片视频,日本av精品在线中文