Address book

更新时间:
复制 MD 格式

This topic describes the JavaScript (JS) APIs for the WVContacts class. You can use these APIs to manage address book permissions when you create H5 applications or miniapps for cross-platform development.

WVContacts.askAuth

Note

This API applies only to WindVane for iOS.

Requests permission to access the address book.

Input parameters

None.

Callback parameters

The callback parameters are passed to the callback method. For iOS versions earlier than 6.0, permission is not required and no callback is triggered. For all other versions, the success callback is always triggered.

  • [int] isAuthed: Specifies whether permission to access the address book is granted. A value of 0 indicates that permission is not granted. A value of 1 indicates that permission is granted.

window.WindVane.call('WVContacts', 'askAuth', {}, function(e) {
        alert(JSON.stringify(e));
});

WVContacts.authStatus

Retrieves the current permission status for accessing the address book.

Input parameters

This operation does not require any input parameters.

Callback parameters

The callback parameters are passed to the callback method. The success callback is always triggered.

  • [boolean] isAuthed: Specifies whether permission to access the address book is granted. A value of 0 indicates that permission is not granted. A value of 1 indicates that permission is granted.

  • [int] status: (WindVane for iOS only) Provides detailed status information for the iOS platform:

    • 0: Not Determined.

    • 1: Restricted.

    • 2: Denied.

    • 3: Authorized.

window.WindVane.call('WVContacts', 'authStatus', {}, function(e) {
        alert(JSON.stringify(e));
});

WVContacts.choose

Opens the address book. After a user selects a contact, the contact's name and phone number are returned to the H5 application.

Input parameters

This operation takes no input parameters.

Callback parameters

The callback parameters are passed to the callback method. If the user selects a contact, the success callback is triggered. Otherwise, the failure callback is triggered.

  • [string] name: The name of the selected contact.

  • [string] phone: The phone number of the selected contact.

window.WindVane.call('WVContacts', 'choose', {}, function(e) {
        alert('success: ' + JSON.stringify(e));
}, function(e) {
        alert('failure: ' + JSON.stringify(e))
});

WVContacts.find

You can find contacts in the address book by name and phone number.

Input parameters

  • [object] filter: The filter conditions for contacts. This object includes the following properties:

    • [string] name: Filters contacts by name.

    • [string] phone: Filters contacts by phone number.

If both phone and name are provided, the search returns contacts that match both criteria. If a contact has multiple phone numbers, each number is returned as a separate record.

Note

On the iOS platform, a contact is a match if its name contains the name value. The same logic applies to its phone number.

Callback parameters

The callback method receives the callback parameters. The success callback is always triggered.

  • [array] contacts: An array of contacts that match the filter conditions. Each contact has the following properties:

    • [string] name: The name of the contact.

    • [string] phone: The phone number of the contact.

var params = {
        // The filter for contacts
        filter: {
                // Find contacts with the specified name
                name: 'Zhang San',
                // Find contacts with the specified phone number
                phone: '123456'
        }
}
window.WindVane.call('WVContacts', 'find', params, function(e) {
        alert(JSON.stringify(e));
});

WVContacts.addPhoneContact

Note

This API is available in Windvane for Android 1.0.3.4 and later.

Add a contact.

Input parameters

  • [string] lastName: The last name.

  • [string] middleName: (Optional) The middle name.

  • [string] middleName: Optional. The middle name.

  • [string] nickName: Optional. The nickname.

  • [string] remark: Optional. The note.

  • [string] mobilePhoneNumber: Optional. The mobile phone number.

  • [string] hostNumber: Optional. The company or home phone number.

  • [string] address: Optional. The address.

  • [string] email: Optional. The email address.

  • [string] organization: Optional. The organization.

  • [string] title: Optional. The job title.

  • [string] photoPath: Optional. The local file path of the profile picture.

Callback parameters

Success callback parameters:

  • None.

Failure callback parameters:

  • [string] msg: The error message.

var params = {
  lastName: 'xxx',
  firstName: 'xxx',
  middleName:'xxx',
  nickName: 'xxx',
  remark: 'xxx',
  mobilePhoneNumber: '+86 12345',
  hostNumber: '12345',
  address: 'Beijing Chaoyang',
  email: 'xxx@xxx.com',
  organization: 'xxx',
  title: 'xxx',
  photoPath: '/storage/emulated/0/DCIM/Camera/xxx.jpg
}

window.WindVane.call('WVContacts', 'addPhoneContact', {}, function(e) {
}, function(e) {
        alert('failure: ' + JSON.stringify(e))
});