提交 80eceb0d 编写于 作者: S shawn_he

update docs

Signed-off-by: Nshawn_he <shawn.he@huawei.com>
上级 9a0ecb8d
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
## Modules to Import ## Modules to Import
``` ```js
import contact from '@ohos.contact'; import contact from '@ohos.contact';
``` ```
...@@ -29,7 +29,7 @@ Adds a contact. This API uses an asynchronous callback to return the result. ...@@ -29,7 +29,7 @@ Adds a contact. This API uses an asynchronous callback to return the result.
**Example** **Example**
``` ```js
contact.addContact({ contact.addContact({
fullName: {fullName: 'xxx'}, fullName: {fullName: 'xxx'},
phoneNumbers: [{phoneNumber: '138xxxxxxxx'}] phoneNumbers: [{phoneNumber: '138xxxxxxxx'}]
...@@ -65,7 +65,7 @@ Adds a contact. This API uses a promise to return the result. ...@@ -65,7 +65,7 @@ Adds a contact. This API uses a promise to return the result.
**Example** **Example**
``` ```js
let promise = contact.addContact({ let promise = contact.addContact({
name: {fullName: 'xxx'}, name: {fullName: 'xxx'},
phoneNumbers: [{phoneNumber: '138xxxxxxxx'}] phoneNumbers: [{phoneNumber: '138xxxxxxxx'}]
...@@ -96,7 +96,7 @@ Deletes a contact based on the specified contact key. This API uses an asynchron ...@@ -96,7 +96,7 @@ Deletes a contact based on the specified contact key. This API uses an asynchron
**Example** **Example**
``` ```js
contact.deleteContact('xxx', (err) => { contact.deleteContact('xxx', (err) => {
if (err) { if (err) {
console.log(`deleteContact callback: err->${JSON.stringify(err)}`); console.log(`deleteContact callback: err->${JSON.stringify(err)}`);
...@@ -129,7 +129,7 @@ Deletes a contact based on the specified contact key. This API uses a promise to ...@@ -129,7 +129,7 @@ Deletes a contact based on the specified contact key. This API uses a promise to
**Example** **Example**
``` ```js
let promise = contact.deleteContact('xxx'); let promise = contact.deleteContact('xxx');
promise.then(() => { promise.then(() => {
console.log(`deleteContact success`); console.log(`deleteContact success`);
...@@ -157,7 +157,7 @@ Updates a contact based on the specified contact information. This API uses an a ...@@ -157,7 +157,7 @@ Updates a contact based on the specified contact information. This API uses an a
**Example** **Example**
``` ```js
contact.updateContact({ contact.updateContact({
name: {fullName: 'xxx'}, name: {fullName: 'xxx'},
phoneNumbers: [{phoneNumber: '138xxxxxxxx'}] phoneNumbers: [{phoneNumber: '138xxxxxxxx'}]
...@@ -190,7 +190,7 @@ Updates a contact based on the specified contact information and attributes. Thi ...@@ -190,7 +190,7 @@ Updates a contact based on the specified contact information and attributes. Thi
**Example** **Example**
``` ```js
contact.updateContact({ contact.updateContact({
fullName: {fullName: 'xxx'}, fullName: {fullName: 'xxx'},
phoneNumbers: [{phoneNumber: '138xxxxxxxx'}] phoneNumbers: [{phoneNumber: '138xxxxxxxx'}]
...@@ -229,7 +229,7 @@ Updates a contact based on the specified contact information and attributes. Thi ...@@ -229,7 +229,7 @@ Updates a contact based on the specified contact information and attributes. Thi
**Example** **Example**
``` ```js
let promise = contact.updateContact({ let promise = contact.updateContact({
fullName: {fullName: 'xxx'}, fullName: {fullName: 'xxx'},
phoneNumbers: [{phoneNumber: '138xxxxxxxx'}] phoneNumbers: [{phoneNumber: '138xxxxxxxx'}]
...@@ -262,7 +262,7 @@ Checks whether the ID of this contact is in the local address book. This API use ...@@ -262,7 +262,7 @@ Checks whether the ID of this contact is in the local address book. This API use
**Example** **Example**
``` ```js
contact.isLocalContact(/*id*/1, (err, data) => { contact.isLocalContact(/*id*/1, (err, data) => {
if (err) { if (err) {
console.log(`isLocalContact callback: err->${JSON.stringify(err)}`); console.log(`isLocalContact callback: err->${JSON.stringify(err)}`);
...@@ -295,7 +295,7 @@ Checks whether the ID of this contact is in the local address book. This API use ...@@ -295,7 +295,7 @@ Checks whether the ID of this contact is in the local address book. This API use
**Example** **Example**
``` ```js
let promise = contact.isLocalContact(/*id*/1); let promise = contact.isLocalContact(/*id*/1);
promise.then((data) => { promise.then((data) => {
console.log(`isLocalContact success: data->${JSON.stringify(data)}`); console.log(`isLocalContact success: data->${JSON.stringify(data)}`);
...@@ -323,7 +323,7 @@ Checks whether a contact is included in my card. This API uses an asynchronous c ...@@ -323,7 +323,7 @@ Checks whether a contact is included in my card. This API uses an asynchronous c
**Example** **Example**
``` ```js
contact.isMyCard(/*id*/1, (err, data) => { contact.isMyCard(/*id*/1, (err, data) => {
if (err) { if (err) {
console.log(`isMyCard callback: err->${JSON.stringify(err)}`); console.log(`isMyCard callback: err->${JSON.stringify(err)}`);
...@@ -356,7 +356,7 @@ Checks whether a contact is included in my card. This API uses a promise to retu ...@@ -356,7 +356,7 @@ Checks whether a contact is included in my card. This API uses a promise to retu
**Example** **Example**
``` ```js
let promise = contact.isMyCard(/*id*/1); let promise = contact.isMyCard(/*id*/1);
promise.then((data) => { promise.then((data) => {
console.log(`isMyCard success: data->${JSON.stringify(data)}`); console.log(`isMyCard success: data->${JSON.stringify(data)}`);
...@@ -383,7 +383,7 @@ Queries my card. This API uses an asynchronous callback to return the result. ...@@ -383,7 +383,7 @@ Queries my card. This API uses an asynchronous callback to return the result.
**Example** **Example**
``` ```js
contact.queryMyCard((err, data) => { contact.queryMyCard((err, data) => {
if (err) { if (err) {
console.log(`queryMyCard callback: err->${JSON.stringify(err)}`); console.log(`queryMyCard callback: err->${JSON.stringify(err)}`);
...@@ -412,7 +412,7 @@ Queries my card based on the specified contact attributes. This API uses an asyn ...@@ -412,7 +412,7 @@ Queries my card based on the specified contact attributes. This API uses an asyn
**Example** **Example**
``` ```js
contact.queryMyCard({ contact.queryMyCard({
attributes:['ATTR_EMAIL', 'ATTR_NAME'] attributes:['ATTR_EMAIL', 'ATTR_NAME']
}, (err, data) => { }, (err, data) => {
...@@ -447,7 +447,7 @@ Queries my card based on the specified contact attributes. This API uses a promi ...@@ -447,7 +447,7 @@ Queries my card based on the specified contact attributes. This API uses a promi
**Example** **Example**
``` ```js
let promise = contact.queryMyCard({ let promise = contact.queryMyCard({
attributes:['ATTR_EMAIL', 'ATTR_NAME'] attributes:['ATTR_EMAIL', 'ATTR_NAME']
}); });
...@@ -465,8 +465,6 @@ selectContact(callback: AsyncCallback&lt;Array&lt;Contact&gt;&gt;): void ...@@ -465,8 +465,6 @@ selectContact(callback: AsyncCallback&lt;Array&lt;Contact&gt;&gt;): void
Selects a contact. This API uses an asynchronous callback to return the result. Selects a contact. This API uses an asynchronous callback to return the result.
This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.
**Permission required**: ohos.permission.READ_CONTACTS **Permission required**: ohos.permission.READ_CONTACTS
**System capability**: SystemCapability.Applications.Contacts and SystemCapability.Applications.ContactsData **System capability**: SystemCapability.Applications.Contacts and SystemCapability.Applications.ContactsData
...@@ -478,7 +476,7 @@ This API is defined but not implemented in OpenHarmony 3.1 Release. It will be a ...@@ -478,7 +476,7 @@ This API is defined but not implemented in OpenHarmony 3.1 Release. It will be a
**Example** **Example**
``` ```js
contact.selectContact((err, data) => { contact.selectContact((err, data) => {
if (err) { if (err) {
console.log(`selectContact callback: err->${JSON.stringify(err)}`); console.log(`selectContact callback: err->${JSON.stringify(err)}`);
...@@ -495,8 +493,6 @@ selectContact(): Promise&lt;Array&lt;Contact&gt;&gt; ...@@ -495,8 +493,6 @@ selectContact(): Promise&lt;Array&lt;Contact&gt;&gt;
Selects a contact. This API uses a promise to return the result. Selects a contact. This API uses a promise to return the result.
This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.
**Permission required**: ohos.permission.READ_CONTACTS **Permission required**: ohos.permission.READ_CONTACTS
**System capability**: SystemCapability.Applications.Contacts and SystemCapability.Applications.ContactsData **System capability**: SystemCapability.Applications.Contacts and SystemCapability.Applications.ContactsData
...@@ -508,7 +504,7 @@ This API is defined but not implemented in OpenHarmony 3.1 Release. It will be a ...@@ -508,7 +504,7 @@ This API is defined but not implemented in OpenHarmony 3.1 Release. It will be a
**Example** **Example**
``` ```js
let promise = contact.selectContact(); let promise = contact.selectContact();
promise.then((data) => { promise.then((data) => {
console.log(`selectContact success: data->${JSON.stringify(data)}`); console.log(`selectContact success: data->${JSON.stringify(data)}`);
...@@ -536,7 +532,7 @@ Queries a contact based on the specified key. This API uses an asynchronous call ...@@ -536,7 +532,7 @@ Queries a contact based on the specified key. This API uses an asynchronous call
**Example** **Example**
``` ```js
contact.queryContact('xxx', (err, data) => { contact.queryContact('xxx', (err, data) => {
if (err) { if (err) {
console.log(`queryContact callback: err->${JSON.stringify(err)}`); console.log(`queryContact callback: err->${JSON.stringify(err)}`);
...@@ -566,7 +562,7 @@ Queries contacts based on the specified key and application. This API uses an as ...@@ -566,7 +562,7 @@ Queries contacts based on the specified key and application. This API uses an as
**Example** **Example**
``` ```js
contact.queryContact('xxx', { contact.queryContact('xxx', {
holderId: 0 holderId: 0
}, (err, data) => { }, (err, data) => {
...@@ -598,7 +594,7 @@ Queries contacts based on the specified key and attributes. This API uses an asy ...@@ -598,7 +594,7 @@ Queries contacts based on the specified key and attributes. This API uses an asy
**Example** **Example**
``` ```js
contact.queryContact('xxx', { contact.queryContact('xxx', {
attributes: ["ATTR_EMAIL", "ATTR_NAME"] attributes: ["ATTR_EMAIL", "ATTR_NAME"]
}, (err, data) => { }, (err, data) => {
...@@ -631,7 +627,7 @@ Queries contacts based on the specified key, application, and attributes. This A ...@@ -631,7 +627,7 @@ Queries contacts based on the specified key, application, and attributes. This A
**Example** **Example**
``` ```js
contact.queryContact('xxx', { contact.queryContact('xxx', {
holderId: 0 holderId: 0
}, { }, {
...@@ -670,7 +666,7 @@ Queries contacts based on the specified key, application, and attributes. This A ...@@ -670,7 +666,7 @@ Queries contacts based on the specified key, application, and attributes. This A
**Example** **Example**
``` ```js
let promise = contact.queryContact('xxx', { let promise = contact.queryContact('xxx', {
holderId: 0 holderId: 0
}, { }, {
...@@ -701,7 +697,7 @@ Queries all contacts. This API uses an asynchronous callback to return the resul ...@@ -701,7 +697,7 @@ Queries all contacts. This API uses an asynchronous callback to return the resul
**Example** **Example**
``` ```js
contact.queryContacts((err, data) => { contact.queryContacts((err, data) => {
if (err) { if (err) {
console.log(`queryContacts callback: err->${JSON.stringify(err)}`); console.log(`queryContacts callback: err->${JSON.stringify(err)}`);
...@@ -730,7 +726,7 @@ Queries all contacts based on the specified application. This API uses an asynch ...@@ -730,7 +726,7 @@ Queries all contacts based on the specified application. This API uses an asynch
**Example** **Example**
``` ```js
contact.queryContacts({ contact.queryContacts({
holderId: 0 holderId: 0
}, (err, data) => { }, (err, data) => {
...@@ -761,7 +757,7 @@ Queries all contacts based on the specified attributes. This API uses an asynchr ...@@ -761,7 +757,7 @@ Queries all contacts based on the specified attributes. This API uses an asynchr
**Example** **Example**
``` ```js
contact.queryContacts({ contact.queryContacts({
attributes: ["ATTR_EMAIL", "ATTR_NAME"] attributes: ["ATTR_EMAIL", "ATTR_NAME"]
}, (err, data) => { }, (err, data) => {
...@@ -793,7 +789,7 @@ Queries all contacts based on the specified application and attributes. This API ...@@ -793,7 +789,7 @@ Queries all contacts based on the specified application and attributes. This API
**Example** **Example**
``` ```js
contact.queryContacts({ contact.queryContacts({
holderId: 0 holderId: 0
}, { }, {
...@@ -831,7 +827,7 @@ Queries all contacts based on the specified application and attributes. This API ...@@ -831,7 +827,7 @@ Queries all contacts based on the specified application and attributes. This API
**Example** **Example**
``` ```js
let promise = contact.queryContacts({ let promise = contact.queryContacts({
holderId: 0 holderId: 0
}, { }, {
...@@ -863,7 +859,7 @@ Queries contacts based on the specified phone number. This API uses an asynchron ...@@ -863,7 +859,7 @@ Queries contacts based on the specified phone number. This API uses an asynchron
**Example** **Example**
``` ```js
contact.queryContactsByPhoneNumber('138xxxxxxxx', (err, data) => { contact.queryContactsByPhoneNumber('138xxxxxxxx', (err, data) => {
if (err) { if (err) {
console.log(`queryContactsByPhoneNumber callback: err->${JSON.stringify(err)}`); console.log(`queryContactsByPhoneNumber callback: err->${JSON.stringify(err)}`);
...@@ -893,7 +889,7 @@ Queries contacts based on the specified phone number and application. This API u ...@@ -893,7 +889,7 @@ Queries contacts based on the specified phone number and application. This API u
**Example** **Example**
``` ```js
contact.queryContactsByPhoneNumber('138xxxxxxxx', { contact.queryContactsByPhoneNumber('138xxxxxxxx', {
holderId: 0 holderId: 0
}, (err, data) => { }, (err, data) => {
...@@ -925,7 +921,7 @@ Queries contacts based on the specified phone number and attributes. This API us ...@@ -925,7 +921,7 @@ Queries contacts based on the specified phone number and attributes. This API us
**Example** **Example**
``` ```js
contact.queryContactsByPhoneNumber('138xxxxxxxx', { contact.queryContactsByPhoneNumber('138xxxxxxxx', {
attributes: ["ATTR_EMAIL", "ATTR_NAME"] attributes: ["ATTR_EMAIL", "ATTR_NAME"]
}, (err, data) => { }, (err, data) => {
...@@ -958,7 +954,7 @@ Queries contacts based on the specified phone number, application, and attribute ...@@ -958,7 +954,7 @@ Queries contacts based on the specified phone number, application, and attribute
**Example** **Example**
``` ```js
contact.queryContactsByPhoneNumber('138xxxxxxxx', { contact.queryContactsByPhoneNumber('138xxxxxxxx', {
holderId: 0 holderId: 0
}, { }, {
...@@ -997,7 +993,7 @@ Queries contacts based on the specified phone number, application, and attribute ...@@ -997,7 +993,7 @@ Queries contacts based on the specified phone number, application, and attribute
**Example** **Example**
``` ```js
let promise = contact.queryContactsByPhoneNumber('138xxxxxxxx', { let promise = contact.queryContactsByPhoneNumber('138xxxxxxxx', {
holderId: 0 holderId: 0
}, { }, {
...@@ -1029,7 +1025,7 @@ Queries contacts based on the specified email address. This API uses an asynchro ...@@ -1029,7 +1025,7 @@ Queries contacts based on the specified email address. This API uses an asynchro
**Example** **Example**
``` ```js
contact.queryContactsByEmail('xxx@email.com', (err, data) => { contact.queryContactsByEmail('xxx@email.com', (err, data) => {
if (err) { if (err) {
console.log(`queryContactsByEmail callback: err->${JSON.stringify(err)}`); console.log(`queryContactsByEmail callback: err->${JSON.stringify(err)}`);
...@@ -1059,7 +1055,7 @@ Queries contacts based on the specified email address and application. This API ...@@ -1059,7 +1055,7 @@ Queries contacts based on the specified email address and application. This API
**Example** **Example**
``` ```js
contact.queryContactsByEmail('xxx@email.com', { contact.queryContactsByEmail('xxx@email.com', {
holderId: 0 holderId: 0
}, (err, data) => { }, (err, data) => {
...@@ -1091,7 +1087,7 @@ Queries contacts based on the specified email address and attributes. This API u ...@@ -1091,7 +1087,7 @@ Queries contacts based on the specified email address and attributes. This API u
**Example** **Example**
``` ```js
contact.queryContactsByEmail('xxx@email.com', { contact.queryContactsByEmail('xxx@email.com', {
attributes: ["ATTR_EMAIL", "ATTR_NAME"] attributes: ["ATTR_EMAIL", "ATTR_NAME"]
}, (err, data) => { }, (err, data) => {
...@@ -1124,7 +1120,7 @@ Queries contacts based on the specified email address, application, and attribut ...@@ -1124,7 +1120,7 @@ Queries contacts based on the specified email address, application, and attribut
**Example** **Example**
``` ```js
contact.queryContactsByEmail('xxx@email.com', { contact.queryContactsByEmail('xxx@email.com', {
holderId: 0 holderId: 0
}, { }, {
...@@ -1163,7 +1159,7 @@ Queries contacts based on the specified email address, application, and attribut ...@@ -1163,7 +1159,7 @@ Queries contacts based on the specified email address, application, and attribut
**Example** **Example**
``` ```js
let promise = contact.queryContactsByEmail('xxx@email.com', { let promise = contact.queryContactsByEmail('xxx@email.com', {
holderId: 0 holderId: 0
}, { }, {
...@@ -1194,7 +1190,7 @@ Queries all groups of this contact. This API uses an asynchronous callback to re ...@@ -1194,7 +1190,7 @@ Queries all groups of this contact. This API uses an asynchronous callback to re
**Example** **Example**
``` ```js
contact.queryGroups((err, data) => { contact.queryGroups((err, data) => {
if (err) { if (err) {
console.log(`queryGroups callback: err->${JSON.stringify(err)}`); console.log(`queryGroups callback: err->${JSON.stringify(err)}`);
...@@ -1223,7 +1219,7 @@ Queries all groups of this contact based on the specified application. This API ...@@ -1223,7 +1219,7 @@ Queries all groups of this contact based on the specified application. This API
**Example** **Example**
``` ```js
contact.queryGroups({ contact.queryGroups({
holderId: 0 holderId: 0
}, (err, data) => { }, (err, data) => {
...@@ -1258,7 +1254,7 @@ Queries all groups of this contact based on the specified application. This API ...@@ -1258,7 +1254,7 @@ Queries all groups of this contact based on the specified application. This API
**Example** **Example**
``` ```js
let promise = contact.queryGroups({ let promise = contact.queryGroups({
holderId: 0 holderId: 0
}); });
...@@ -1287,7 +1283,7 @@ Queries all applications that have created contacts. This API uses an asynchrono ...@@ -1287,7 +1283,7 @@ Queries all applications that have created contacts. This API uses an asynchrono
**Example** **Example**
``` ```js
contact.queryHolders((err, data) => { contact.queryHolders((err, data) => {
if (err) { if (err) {
console.log(`queryHolders callback: err->${JSON.stringify(err)}`); console.log(`queryHolders callback: err->${JSON.stringify(err)}`);
...@@ -1315,7 +1311,7 @@ Queries all applications that have created contacts. This API uses a promise to ...@@ -1315,7 +1311,7 @@ Queries all applications that have created contacts. This API uses a promise to
**Example** **Example**
``` ```js
let promise = contact.queryHolders(); let promise = contact.queryHolders();
promise.then((data) => { promise.then((data) => {
console.log(`queryHolders success: data->${JSON.stringify(data)}`); console.log(`queryHolders success: data->${JSON.stringify(data)}`);
...@@ -1343,7 +1339,7 @@ Queries the key of a contact based on the specified contact ID. This API uses an ...@@ -1343,7 +1339,7 @@ Queries the key of a contact based on the specified contact ID. This API uses an
**Example** **Example**
``` ```js
contact.queryKey(/*id*/1, (err, data) => { contact.queryKey(/*id*/1, (err, data) => {
if (err) { if (err) {
console.log(`queryKey callback: err->${JSON.stringify(err)}`); console.log(`queryKey callback: err->${JSON.stringify(err)}`);
...@@ -1373,7 +1369,7 @@ Queries the key of a contact based on the specified contact ID and application. ...@@ -1373,7 +1369,7 @@ Queries the key of a contact based on the specified contact ID and application.
**Example** **Example**
``` ```js
contact.queryKey(id, { contact.queryKey(id, {
holderId:1 holderId:1
}, (err, data) => { }, (err, data) => {
...@@ -1409,7 +1405,7 @@ Queries the key of a contact based on the specified contact ID and application. ...@@ -1409,7 +1405,7 @@ Queries the key of a contact based on the specified contact ID and application.
**Example** **Example**
``` ```js
let promise = contact.queryKey(id, { let promise = contact.queryKey(id, {
holderId: 0 holderId: 0
}); });
...@@ -1462,7 +1458,7 @@ Defines a contact. ...@@ -1462,7 +1458,7 @@ Defines a contact.
Create contact data in JSON format: Create contact data in JSON format:
``` ```js
let myContact = { let myContact = {
phoneNumbers: [{ phoneNumbers: [{
phoneNumber: "138xxxxxxxx" phoneNumber: "138xxxxxxxx"
...@@ -1480,7 +1476,7 @@ let myContact = { ...@@ -1480,7 +1476,7 @@ let myContact = {
Or, create data by configuring a new Contact object. Or, create data by configuring a new Contact object.
``` ```js
let myContact = new contact.Contact(); let myContact = new contact.Contact();
let name = new contact.Name(); let name = new contact.Name();
name.fullName = "fullName"; name.fullName = "fullName";
...@@ -1508,7 +1504,7 @@ If **null** is passed, all attributes are queried by default. ...@@ -1508,7 +1504,7 @@ If **null** is passed, all attributes are queried by default.
Create contact data in JSON format: Create contact data in JSON format:
``` ```js
let contactAttributes = { let contactAttributes = {
attributes: [ attributes: [
contact.Attribute.ATTR_EMAIL, contact.Attribute.ATTR_EMAIL,
...@@ -1521,7 +1517,7 @@ let contactAttributes = { ...@@ -1521,7 +1517,7 @@ let contactAttributes = {
Or, create data by configuring a **ContactAttributes** object. Or, create data by configuring a **ContactAttributes** object.
``` ```js
let contactAttributes = new contact.ContactAttributes(); let contactAttributes = new contact.ContactAttributes();
contactAttributes.attributes = ["ATTR_EMAIL"]; contactAttributes.attributes = ["ATTR_EMAIL"];
``` ```
...@@ -1555,7 +1551,7 @@ Enumerates contact attributes. ...@@ -1555,7 +1551,7 @@ Enumerates contact attributes.
Create contact data in JSON format: Create contact data in JSON format:
``` ```js
let attributes = [contact.Attribute.ATTR_EMAIL, contact.Attribute.ATTR_NAME, contact.Attribute.ATTR_PHONE]; let attributes = [contact.Attribute.ATTR_EMAIL, contact.Attribute.ATTR_NAME, contact.Attribute.ATTR_PHONE];
``` ```
...@@ -1591,7 +1587,7 @@ Defines a contact's email. ...@@ -1591,7 +1587,7 @@ Defines a contact's email.
Create contact data in JSON format: Create contact data in JSON format:
``` ```js
let email = { let email = {
email: "xxx@email.com", email: "xxx@email.com",
displayName: "displayName" displayName: "displayName"
...@@ -1601,7 +1597,7 @@ let email = { ...@@ -1601,7 +1597,7 @@ let email = {
Or, create data by configuring an **Email** object. Or, create data by configuring an **Email** object.
``` ```js
let email = new contact.Email(); let email = new contact.Email();
email.email = "xxx@email.com"; email.email = "xxx@email.com";
``` ```
...@@ -1624,7 +1620,7 @@ Defines an application that creates the contact. ...@@ -1624,7 +1620,7 @@ Defines an application that creates the contact.
Create contact data in JSON format: Create contact data in JSON format:
``` ```js
let holder = { let holder = {
holderId: 0 holderId: 0
}; };
...@@ -1632,7 +1628,7 @@ let holder = { ...@@ -1632,7 +1628,7 @@ let holder = {
Or, create data by configuring a **Holder** object. Or, create data by configuring a **Holder** object.
``` ```js
let holder = new contact.Holder(); let holder = new contact.Holder();
holder.holderId = 0; holder.holderId = 0;
``` ```
...@@ -1668,7 +1664,7 @@ Defines a contact's event. ...@@ -1668,7 +1664,7 @@ Defines a contact's event.
Create contact data in JSON format: Create contact data in JSON format:
``` ```js
let event = { let event = {
eventDate: "xxxxxx" eventDate: "xxxxxx"
}; };
...@@ -1676,7 +1672,7 @@ let event = { ...@@ -1676,7 +1672,7 @@ let event = {
Or, create data by configuring an **Event** object. Or, create data by configuring an **Event** object.
``` ```js
let event = new contact.Event(); let event = new contact.Event();
event.eventDate = "xxxxxx"; event.eventDate = "xxxxxx";
``` ```
...@@ -1698,7 +1694,7 @@ Defines a contact group. ...@@ -1698,7 +1694,7 @@ Defines a contact group.
Create contact data in JSON format: Create contact data in JSON format:
``` ```js
let group = { let group = {
groupId: 1, groupId: 1,
title: "title" title: "title"
...@@ -1707,7 +1703,7 @@ let group = { ...@@ -1707,7 +1703,7 @@ let group = {
Or, create data by configuring a **Group** object. Or, create data by configuring a **Group** object.
``` ```js
let group = new contact.Group(); let group = new contact.Group();
group.title = "title"; group.title = "title";
``` ```
...@@ -1747,7 +1743,7 @@ Enumerates IM addresses. ...@@ -1747,7 +1743,7 @@ Enumerates IM addresses.
Create contact data in JSON format: Create contact data in JSON format:
``` ```js
let imAddress = { let imAddress = {
imAddress: "imAddress", imAddress: "imAddress",
labelName: "labelName" labelName: "labelName"
...@@ -1757,7 +1753,7 @@ let imAddress = { ...@@ -1757,7 +1753,7 @@ let imAddress = {
Or, create data by configuring an **ImAddress** object. Or, create data by configuring an **ImAddress** object.
``` ```js
let imAddress = new contact.ImAddress(); let imAddress = new contact.ImAddress();
imAddress.imAddress = "imAddress"; imAddress.imAddress = "imAddress";
``` ```
...@@ -1786,7 +1782,7 @@ Defines a contact's name. ...@@ -1786,7 +1782,7 @@ Defines a contact's name.
Create contact data in JSON format: Create contact data in JSON format:
``` ```js
let name = { let name = {
familyName: "familyName", familyName: "familyName",
fullName: "fullName" fullName: "fullName"
...@@ -1795,7 +1791,7 @@ let name = { ...@@ -1795,7 +1791,7 @@ let name = {
Or, create data by configuring a **Name** object. Or, create data by configuring a **Name** object.
``` ```js
let name = new contact.Name(); let name = new contact.Name();
name.familyName = "familyName"; name.familyName = "familyName";
name.fullName = "fullName"; name.fullName = "fullName";
...@@ -1817,7 +1813,7 @@ Defines a contact's nickname. ...@@ -1817,7 +1813,7 @@ Defines a contact's nickname.
Create contact data in JSON format: Create contact data in JSON format:
``` ```js
let nickName = { let nickName = {
nickName: "nickName" nickName: "nickName"
}; };
...@@ -1825,7 +1821,7 @@ let nickName = { ...@@ -1825,7 +1821,7 @@ let nickName = {
Or, create data by configuring a **NickName** object. Or, create data by configuring a **NickName** object.
``` ```js
let nickName = new contact.NickName(); let nickName = new contact.NickName();
nickName.nickName = "nickName"; nickName.nickName = "nickName";
``` ```
...@@ -1846,7 +1842,7 @@ Defines a contact's note. ...@@ -1846,7 +1842,7 @@ Defines a contact's note.
Create contact data in JSON format: Create contact data in JSON format:
``` ```js
let note = { let note = {
noteContent: "noteContent" noteContent: "noteContent"
}; };
...@@ -1854,7 +1850,7 @@ let note = { ...@@ -1854,7 +1850,7 @@ let note = {
Or, create data by configuring a **Note** object. Or, create data by configuring a **Note** object.
``` ```js
let note = new contact.Note(); let note = new contact.Note();
note.noteContent = "noteContent"; note.noteContent = "noteContent";
``` ```
...@@ -1876,7 +1872,7 @@ Defines a contact's organization. ...@@ -1876,7 +1872,7 @@ Defines a contact's organization.
Create contact data in JSON format: Create contact data in JSON format:
``` ```js
let organization = { let organization = {
name: "name", name: "name",
title: "title" title: "title"
...@@ -1885,7 +1881,7 @@ let organization = { ...@@ -1885,7 +1881,7 @@ let organization = {
Or, create data by configuring an **Organization** object. Or, create data by configuring an **Organization** object.
``` ```js
let organization = new contact.Organization(); let organization = new contact.Organization();
organization.name = "name"; organization.name = "name";
organization.title = "title"; organization.title = "title";
...@@ -1939,7 +1935,7 @@ Defines a contact's phone number. ...@@ -1939,7 +1935,7 @@ Defines a contact's phone number.
Create contact data in JSON format: Create contact data in JSON format:
``` ```js
let phoneNumber = { let phoneNumber = {
phoneNumber: "138xxxxxxxx", phoneNumber: "138xxxxxxxx",
labelId: contact.PhoneNumber.NUM_HOME labelId: contact.PhoneNumber.NUM_HOME
...@@ -1948,7 +1944,7 @@ let phoneNumber = { ...@@ -1948,7 +1944,7 @@ let phoneNumber = {
Or, create data by configuring a new **PhoneNumber** object. Or, create data by configuring a new **PhoneNumber** object.
``` ```js
let phoneNumber = new contact.PhoneNumber(); let phoneNumber = new contact.PhoneNumber();
phoneNumber.phoneNumber = "138xxxxxxxx"; phoneNumber.phoneNumber = "138xxxxxxxx";
``` ```
...@@ -1969,7 +1965,7 @@ Defines a contact's portrait. ...@@ -1969,7 +1965,7 @@ Defines a contact's portrait.
Create contact data in JSON format: Create contact data in JSON format:
``` ```js
let portrait = { let portrait = {
uri: "uri" uri: "uri"
}; };
...@@ -1977,7 +1973,7 @@ let portrait = { ...@@ -1977,7 +1973,7 @@ let portrait = {
Or, create data by configuring a new **Portrait** object. Or, create data by configuring a new **Portrait** object.
``` ```js
let portrait = new contact.Portrait(); let portrait = new contact.Portrait();
portrait.uri = "uri"; portrait.uri = "uri";
``` ```
...@@ -2020,7 +2016,7 @@ Defines a contact's postal address. ...@@ -2020,7 +2016,7 @@ Defines a contact's postal address.
Create contact data in JSON format: Create contact data in JSON format:
``` ```js
let postalAddress = { let postalAddress = {
city: "city" city: "city"
}; };
...@@ -2028,7 +2024,7 @@ let postalAddress = { ...@@ -2028,7 +2024,7 @@ let postalAddress = {
Or, create data by configuring a new **PostalAddress** object. Or, create data by configuring a new **PostalAddress** object.
``` ```js
let postalAddress = new contact.PostalAddress(); let postalAddress = new contact.PostalAddress();
postalAddress.city = "city"; postalAddress.city = "city";
``` ```
...@@ -2075,7 +2071,7 @@ Defines a contact's relationship. ...@@ -2075,7 +2071,7 @@ Defines a contact's relationship.
Create contact data in JSON format: Create contact data in JSON format:
``` ```js
let relation = { let relation = {
relationName: "relationName", relationName: "relationName",
labelId: contact.Relation.RELATION_ASSISTANT labelId: contact.Relation.RELATION_ASSISTANT
...@@ -2084,7 +2080,7 @@ let relation = { ...@@ -2084,7 +2080,7 @@ let relation = {
Or, create data by configuring a new **Relation** object. Or, create data by configuring a new **Relation** object.
``` ```js
let relation = new contact.Relation(); let relation = new contact.Relation();
relation.relationName = "relationName"; relation.relationName = "relationName";
relation.labelId = contact.Relation.RELATION_ASSISTANT; relation.labelId = contact.Relation.RELATION_ASSISTANT;
...@@ -2121,7 +2117,7 @@ Defines a contact's SIP address. ...@@ -2121,7 +2117,7 @@ Defines a contact's SIP address.
Create contact data in JSON format: Create contact data in JSON format:
``` ```js
var sipAddress = { var sipAddress = {
sipAddress: "sipAddress" sipAddress: "sipAddress"
}; };
...@@ -2129,7 +2125,7 @@ var sipAddress = { ...@@ -2129,7 +2125,7 @@ var sipAddress = {
Or, create data by configuring a new **SipAddress** object. Or, create data by configuring a new **SipAddress** object.
``` ```js
let sipAddress = new contact.SipAddress(); let sipAddress = new contact.SipAddress();
sipAddress.sipAddress = "sipAddress"; sipAddress.sipAddress = "sipAddress";
``` ```
...@@ -2150,7 +2146,7 @@ Defines a contact's website. ...@@ -2150,7 +2146,7 @@ Defines a contact's website.
Create contact data in JSON format: Create contact data in JSON format:
``` ```js
let website = { let website = {
website: "website" website: "website"
}; };
...@@ -2158,7 +2154,7 @@ let website = { ...@@ -2158,7 +2154,7 @@ let website = {
Or, create data by configuring a new **Website** object. Or, create data by configuring a new **Website** object.
``` ```js
let website = new contact.Website(); let website = new contact.Website();
website.website = "website"; website.website = "website";
``` ```
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
>![](public_sys-resources/icon-note.gif) **NOTE:** >![](public_sys-resources/icon-note.gif) **NOTE:**
>The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. >The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> >
>Newly added APIs are defined but not implemented in OpenHarmony 3.1 Release. They will be available for use in OpenHarmony 3.1 MR.
You can use WebSocket to establish a bidirectional connection between a server and a client. Before doing this, you need to use the [createWebSocket](#websocketcreatewebsocket) API to create a [WebSocket](#websocket) object and then use the [connect](#connect) API to connect to the server. If the connection is successful, the client will receive a callback of the [open](#onopen) event. Then, the client can communicate with the server using the [send](#send) API. When the server sends a message to the client, the client will receive a callback of the [message](#onmessage) event. If the client no longer needs this connection, it can call the [close](#close) API to disconnect from the server. Then, the client will receive a callback of the [close](#onclose) event. You can use WebSocket to establish a bidirectional connection between a server and a client. Before doing this, you need to use the [createWebSocket](#websocketcreatewebsocket) API to create a [WebSocket](#websocket) object and then use the [connect](#connect) API to connect to the server. If the connection is successful, the client will receive a callback of the [open](#onopen) event. Then, the client can communicate with the server using the [send](#send) API. When the server sends a message to the client, the client will receive a callback of the [message](#onmessage) event. If the client no longer needs this connection, it can call the [close](#close) API to disconnect from the server. Then, the client will receive a callback of the [close](#onclose) event.
...@@ -12,13 +11,13 @@ If an error occurs in any of the preceding processes, the client will receive a ...@@ -12,13 +11,13 @@ If an error occurs in any of the preceding processes, the client will receive a
## Modules to Import ## Modules to Import
``` ```js
import webSocket from '@ohos.net.webSocket'; import webSocket from '@ohos.net.webSocket';
``` ```
## Complete Example ## Complete Example
``` ```js
import webSocket from '@ohos.net.webSocket'; import webSocket from '@ohos.net.webSocket';
var defaultIpAddress = "ws://"; var defaultIpAddress = "ws://";
...@@ -78,7 +77,7 @@ Creates a WebSocket connection. You can use this API to create or close a WebSoc ...@@ -78,7 +77,7 @@ Creates a WebSocket connection. You can use this API to create or close a WebSoc
**Example** **Example**
``` ```js
let ws = webSocket.createWebSocket(); let ws = webSocket.createWebSocket();
``` ```
...@@ -107,7 +106,7 @@ Initiates a WebSocket request to establish a WebSocket connection to a given URL ...@@ -107,7 +106,7 @@ Initiates a WebSocket request to establish a WebSocket connection to a given URL
**Example** **Example**
``` ```js
let ws = webSocket.createWebSocket(); let ws = webSocket.createWebSocket();
let url = "ws://" let url = "ws://"
ws.connect(url, (err, value) => { ws.connect(url, (err, value) => {
...@@ -141,7 +140,7 @@ Initiates a WebSocket request carrying specified options to establish a WebSocke ...@@ -141,7 +140,7 @@ Initiates a WebSocket request carrying specified options to establish a WebSocke
**Example** **Example**
``` ```js
let ws = webSocket.createWebSocket(); let ws = webSocket.createWebSocket();
let url = "ws://" let url = "ws://"
ws.connect(url, { ws.connect(url, {
...@@ -184,7 +183,7 @@ Initiates a WebSocket request carrying specified options to establish a WebSocke ...@@ -184,7 +183,7 @@ Initiates a WebSocket request carrying specified options to establish a WebSocke
**Example** **Example**
``` ```js
let ws = webSocket.createWebSocket(); let ws = webSocket.createWebSocket();
let url = "ws://" let url = "ws://"
let promise = ws.connect(url); let promise = ws.connect(url);
...@@ -215,7 +214,7 @@ Sends data through a WebSocket connection. This API uses an asynchronous callbac ...@@ -215,7 +214,7 @@ Sends data through a WebSocket connection. This API uses an asynchronous callbac
**Example** **Example**
``` ```js
let ws = webSocket.createWebSocket(); let ws = webSocket.createWebSocket();
let url = "ws://" let url = "ws://"
ws.connect(url, (err, value) => { ws.connect(url, (err, value) => {
...@@ -254,7 +253,7 @@ Sends data through a WebSocket connection. This API uses a promise to return the ...@@ -254,7 +253,7 @@ Sends data through a WebSocket connection. This API uses a promise to return the
**Example** **Example**
``` ```js
let ws = webSocket.createWebSocket(); let ws = webSocket.createWebSocket();
let url = "ws://" let url = "ws://"
ws.connect(url, (err, value) => { ws.connect(url, (err, value) => {
...@@ -286,7 +285,7 @@ Closes a WebSocket connection. This API uses an asynchronous callback to return ...@@ -286,7 +285,7 @@ Closes a WebSocket connection. This API uses an asynchronous callback to return
**Example** **Example**
``` ```js
let ws = webSocket.createWebSocket(); let ws = webSocket.createWebSocket();
let url = "ws://" let url = "ws://"
ws.close((err, value) => { ws.close((err, value) => {
...@@ -318,7 +317,7 @@ Closes a WebSocket connection carrying specified options such as **code** and ** ...@@ -318,7 +317,7 @@ Closes a WebSocket connection carrying specified options such as **code** and **
**Example** **Example**
``` ```js
let ws = webSocket.createWebSocket(); let ws = webSocket.createWebSocket();
let url = "ws://" let url = "ws://"
ws.close({ ws.close({
...@@ -358,7 +357,7 @@ Closes a WebSocket connection carrying specified options such as **code** and ** ...@@ -358,7 +357,7 @@ Closes a WebSocket connection carrying specified options such as **code** and **
**Example** **Example**
``` ```js
let ws = webSocket.createWebSocket(); let ws = webSocket.createWebSocket();
let url = "ws://" let url = "ws://"
let promise = ws.close({ let promise = ws.close({
...@@ -391,7 +390,7 @@ Enables listening for the **open** events of a WebSocket connection. This API us ...@@ -391,7 +390,7 @@ Enables listening for the **open** events of a WebSocket connection. This API us
**Example** **Example**
``` ```js
let ws = webSocket.createWebSocket(); let ws = webSocket.createWebSocket();
ws.on('open', (err, value) => { ws.on('open', (err, value) => {
console.log("on open, status:" + value.status + ", message:" + value.message); console.log("on open, status:" + value.status + ", message:" + value.message);
...@@ -419,7 +418,7 @@ Disables listening for the **open** events of a WebSocket connection. This API u ...@@ -419,7 +418,7 @@ Disables listening for the **open** events of a WebSocket connection. This API u
**Example** **Example**
``` ```js
let ws = webSocket.createWebSocket(); let ws = webSocket.createWebSocket();
let callback1 = (err, value) => { let callback1 = (err, value) => {
console.log("on open, status:" + value.status + ", message:" + value.message); console.log("on open, status:" + value.status + ", message:" + value.message);
...@@ -451,7 +450,7 @@ Enables listening for the **message** events of a WebSocket connection. This API ...@@ -451,7 +450,7 @@ Enables listening for the **message** events of a WebSocket connection. This API
**Example** **Example**
``` ```js
let ws = webSocket.createWebSocket(); let ws = webSocket.createWebSocket();
ws.on('message', (err, value) => { ws.on('message', (err, value) => {
console.log("on message, message:" + value); console.log("on message, message:" + value);
...@@ -480,7 +479,7 @@ Disables listening for the **message** events of a WebSocket connection. This AP ...@@ -480,7 +479,7 @@ Disables listening for the **message** events of a WebSocket connection. This AP
**Example** **Example**
``` ```js
let ws = webSocket.createWebSocket(); let ws = webSocket.createWebSocket();
ws.off('message'); ws.off('message');
``` ```
...@@ -503,7 +502,7 @@ Enables listening for the **close** events of a WebSocket connection. This API u ...@@ -503,7 +502,7 @@ Enables listening for the **close** events of a WebSocket connection. This API u
**Example** **Example**
``` ```js
let ws = webSocket.createWebSocket(); let ws = webSocket.createWebSocket();
ws.on('close', (err, value) => { ws.on('close', (err, value) => {
console.log("on close, code is " + value.code + ", reason is " + value.reason); console.log("on close, code is " + value.code + ", reason is " + value.reason);
...@@ -532,7 +531,7 @@ Disables listening for the **close** events of a WebSocket connection. This API ...@@ -532,7 +531,7 @@ Disables listening for the **close** events of a WebSocket connection. This API
**Example** **Example**
``` ```js
let ws = webSocket.createWebSocket(); let ws = webSocket.createWebSocket();
ws.off('close'); ws.off('close');
``` ```
...@@ -556,7 +555,7 @@ Enables listening for the **error** events of a WebSocket connection. This API u ...@@ -556,7 +555,7 @@ Enables listening for the **error** events of a WebSocket connection. This API u
**Example** **Example**
``` ```js
let ws = webSocket.createWebSocket(); let ws = webSocket.createWebSocket();
ws.on('error', (err) => { ws.on('error', (err) => {
console.log("on error, error:" + JSON.stringify(err)) console.log("on error, error:" + JSON.stringify(err))
...@@ -584,7 +583,7 @@ Disables listening for the **error** events of a WebSocket connection. This API ...@@ -584,7 +583,7 @@ Disables listening for the **error** events of a WebSocket connection. This API
**Example** **Example**
``` ```js
let ws = webSocket.createWebSocket(); let ws = webSocket.createWebSocket();
ws.off('error'); ws.off('error');
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册