...
Code Block |
---|
|
cordova plugin add cordova-plugin-contacts |
Usage
Create Contact
Assume that there is a "Create Contact" button on your mobile application. A new contact is created when that button is clicked. The following is a sample code snippet that can be used in the listener JS file to create a new contact:
Code Block |
---|
|
//* The Thisfollowing function creates a new contact on the mobile device.
* Here, CFEC.CLICK is the Canvas event that can be used to capture the button clicked action.
* CREATE is the form item ID for the "CREATE CONTACT" button.
*/
this.fm.registerHandler("cbxclick"CFEC.CLICK, "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);
});
// The Thisfollowing function is executed when new contact is successfully created on the mobile device.
function onSuccess(success)
{
showAlert("saved" + success);
}
// The Thisfollowing function is executed when new contact is not created on the mobile device.
function onError(err)
{
showAlert("not saved" + err);
}
|
View Contact
Code Block |
---|
|
//* The Thisfollowing function picks a phone number from the contact on the mobile device.
* Here, CFEC.CLICK is the Canvas event that can be used to capture the button clicked action.
* PICK_PHONENO is the form item ID for the "PICK PHONE NUMBER" button.
*/
this.fm.registerHandler("cbxclick"CFEC.CLICK, "PICK_PHONENO",
function (fm, event, fieldName, value)
{
canvas.env.contacts.pickPhoneNumbers(function (phoneNumber)
{
showAlert(phoneNumber);
}, function (err)
{
showAlert(err);
});
});
//* The Thisfollowing function picks a name from the contact on the mobile device.
* Here, PICK is the form item ID for the "PICK" button.
*/
this.fm.registerHandler("cbxclick"CFEC.CLICK, "PICK",
function (fm, event, fieldName, value)
{
canvas.env.contacts.pickContact(function (message)
{
showAlert(cbx.encode(message));
}, function (err)
{
showAlert(err);
});
});
|