Page tree
Skip to end of metadata
Go to start of metadata

Smartface allows you to access the device information and you can use this information such as Contacts in your application. This guide explains how to retrieve Contacts information.

Device Contacts

You can access the Contacts in the device which allows you to add or pick a contact from it with typing:

Device.Contacts.

See also: Device.Contacts in the docs.

Adding a Contact

You can add new contact information into your device with this function : 

Device.Contacts.addContact({ //adding to device contacts
	firstName : "John",
	lastName : "Malkovich", //contact info
	phoneNumber : "1111111",
	onSuccess : function () {
		alert("The record has been added"); //inform user if operation success
	},
	onError : function () {
		alert("failed to add your record"); //inform user if gives an error.
	}
});

Getting All Contacts

All contacts data will be fetched and returned as an array of contacts in a callback function. By defining “fields” parameter, fetched parameters of the contact details can be set. The value of the default field is “all” if not set. Multiple fields are defined with one space between values (e.g.“firstName lastName phone”). Fields paramater is optional. This function may work a little bit slow, since it’s trying to get all phonebook information. Also, native iOS function is the same.

var people = Device.Contacts.getAll({
		fields : ["firstName", "lastName", "phone"], // can be "all"
		onSuccess : function (e) {
			for (i = 0; i < e.length; i++) {
				// you can move in all the contacts with an easy for loop
	});

Pick a Contact

This method allows users to pick a contact from the Device. Here is a list of values you can pick from the Device:

Single value fields:

NAMETYPE

firstName

String

middleName

String

lastName

String

fullName

String

organization

String

jobTitle

String

department

String

birthday

String

created

String

modified

String

kind

String

note

String

Multi value fields:

NAMETYPEDESCRIPTION
phone String []array of string
email String []array of string
address String [] array of string {country, countryCode, city, state, street, zip}
instantMessage Object [] array of object {service,username}
socialProfile Object []array of object {service, username}
relatedNames String []array of string
date String []array of string
url String []array of string
photo image []Original contact photo. Can be set to an image or canvas object

Code Sample:

Device.Contacts.pick({
	showDetail : false, //iOS only
	onSuccess : function (e) {
		Image1.image = e.photo; //transferring contact photo into your image component
	},
	onCancel : function (e) { //when user cancels operation...
		alert("cancelled");
	},
	onError : function (e) { //when you get an error...
		alert("error");
	}
});