(联系人)Contacts
2017-07-04 本文已影响63人
待花谢花开
Contacts
访问和管理设备上的联系人。
Repo(备用): https://github.com/apache/cordova-plugin-contacts
Installation(安装)
1.安装Cordova和Ionic原生插件:
$ ionic cordova plugin add cordova-plugin-contacts
$ npm install --save @ionic-native/contacts
Supported platforms(支持平台)
Android
BlackBerry 10
Firefox OS
iOS
Ubuntu
Windows
Windows Phone 8
Usage(用法)
import { Contacts, Contact, ContactField, ContactName } from '@ionic-native/contacts';
constructor(private contacts: Contacts) { }
let contact: Contact = this.contacts.create();
contact.name = new ContactName(null, 'Smith', 'John');
contact.phoneNumbers = [new ContactField('mobile', '6471234567')];
contact.save().then(
() => console.log('Contact saved!', contact),
(error: any) => console.error('Error saving contact.', error)
);
Instance Members(实例)
创建一个联系人。
****Returns:** Contact
返回一个Contact对象
在联系人列表中搜索联系人。
参数 | 类型 | 详情 |
---|---|---|
fields | ContactFieldType[ | 联系人字段用作搜索限定词 |
options | IContactFindOptions | 查询的可选选项 |
****Returns:** Promise<Contact[]>
返回一个包含搜索结果的可解析的Promise(一个Contact对象数组)
选择一个联系人。
****Returns:** Promise<Contact>
返回包含所选联系人的可解析的promise
Contact
Instance Members(实例成员)
IContactProperties
参数 | 类型 | 详情 |
---|---|---|
id | string | 全局唯一标识符(可选) |
displayName | string | 此联系人的名称,适合向最终用户显示(可选) |
name | IContactName | 包含人员姓名的所有组成部分的对象(可选) |
nickname | string | 一个昵称来定位联系人(可选) |
phoneNumbers | IContactField[] | 所有联系人电话号码的数组(可选) |
emails | IContactField[] | 所有联系人的电子邮件地址的数组(可选) |
addresses | IContactAddress[] | 所有联系人地址的数组(可选) |
ims | IContactField[] | 所有联系人的IM地址的数组(可选) |
organizations | IContactOrganization[] | 所有联系人组织的阵列(可选) |
birthday | Date | 联系人的生日(可选) |
note | string | 关于联系人的备注(可选) |
photos | IContactField[] | 联系人的照片数组(可选) |
categories | IContactField[] | 与联系人关联的所有用户定义类别的数组(可选) |
urls | IContactField[] | 与联系人关联的一系列网页(可选) |
IContactError
参数 | 类型 | 详情 |
---|---|---|
code | number | 错误码 |
message | string | 错误信息 |
参数 | 类型 | 详情 |
---|---|---|
formatted | string | 联系人的完整名称(可选) |
familyName | string | 联系人的姓氏(可选) |
givenName | string | 联系人的给定名称(可选) |
middleName | string | 联络人的中间名(可选) |
honorificPrefix | string | 联系人的前缀(示例先生或博士)(可选) |
honorificSuffix | string | 联系人的后缀(例如Esq。)(可选) |
IContactField
参数 | 类型 | 详情 |
---|---|---|
type | string | 一个字符串,表示这是什么类型的字段,例如家庭(可选) |
value | string | 字段的值,如电话号码或电子邮件地址。(可选) |
pref | boolean | 如果此ContactField包含用户的首选值,则设置为true (可选) |
IContactAddress
参数 | 类型 | 详情 |
---|---|---|
pref | boolean | 如果此ContactAddress包含用户的首选值,则设置为true (可选) |
type | string | 一个字符串,表示这是什么类型的字段,例如家庭(可选) |
formatted | string | 格式化显示的完整地址(可选) |
streetAddress | string | 完整的街道地址(可选) |
locality | string | 城市或地方(可选) |
region | string | 国家或地区(可选) |
postalCode | string | 邮政编码(可选) |
country | string | 国家名称(可选) |
IContactOrganization
参数 | 类型 | 详情 |
---|---|---|
pref | boolean | 如果此联系人组织包含用户的首选值,则设置为true (可选) |
type | string | 一个字符串,表示这是什么类型的字段,例如家庭(可选) |
name | string | 组织名称(可选) |
department | string | 合同工作的部门(可选) |
title | string | 联系人在组织的标题(可选) |
IContactFindOptions
参数 | 类型 | 详情 |
---|---|---|
filter | string | 用于查找navigator.contacts的搜索字符串(可选) |
multiple | boolean | 确定find操作是否返回多个navigator.contacts。 默认为false。(可选) |
desiredFields | string[] | 联系人域返回。 如果指定,则所产生的Contact对象仅为这些字段提供值(可选) |
hasPhoneNumber | boolean | (仅适用于Android):过滤搜索,仅返回通知电话号码的联系人(可选) |