Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

This feature enables your mobile application to create, remove, and search through contacts on the mobile device.

Supported Platforms

This feature is supported in the following platforms:

  • iOS
  • Android

Installation

Execute the following command in your Cordova project directory:

cordova plugin add cordova-plugin-contacts

Usage

Create Contact

// This function creates a new contact on the mobile device
this.fm.registerHandler("cbxclick", "CREATE", 
                        function (fm, event, fieldName, value) 
						{
            				var params = 
							{
                				"displayName": "CT",
								"firstName": "Canvas",
								"lastName": "Technology",
								"workNumber": "212-555-1234",
								"mobileNumber": "917-555-5432",
								"homeNumber": "2345234567"
            				};
            				var contact = canvas.env.contacts.create(params, onSuccess, onError);
 						});

// This function is executed when new contact is successfully created on the mobile device.
function onSuccess(success) 
{
    showAlert("saved" + success);
}

// This function is executed when new contact is not created on the mobile device.
function onError(err) 
{
    showAlert("not saved" + err);
}

View Contact

// This function picks a phone number from the contact on the mobile device.
this.fm.registerHandler("cbxclick", "PICK_PHONENO", 
                        function (fm, event, fieldName, value) 
						{
            				canvas.env.contacts.pickPhoneNumbers(function (phoneNumber) 
							{
                				showAlert(phoneNumber);
            				}, function (err) 
							{
                				showAlert(err);
            				});
});

// This function picks a name from the contact on the mobile device.
this.fm.registerHandler("cbxclick", "PICK", 
                        function (fm, event, fieldName, value) 
						{
            				canvas.env.contacts.pickContact(function (message) 
							{
                				showAlert(cbx.encode(message));
            				}, function (err) 
							{
                				showAlert(err);
            				});
});


  • No labels