Skip to main content
Version: 7.1.0

Contacts

API Reference: Device.Contacts

Contacts is used to access the contact list on the device.

Permissions

To add a contact, you have to guarantee WRITE_CONTACT permission.

To get a contact, you have to guarantee READ_CONTACT permission.

TypeScript
import PageSampleDesign from "generated/pages/pageSample";
import { Route, Router } from "@smartface/router";
import Application from "@smartface/native/application";
import Contacts from "@smartface/native/device/contacts";
import Button from "@smartface/native/ui/button";
import Device from "@smartface/native/device";
import Permission from '@smartface/native/device/permission';
import System from "@smartface/native/device/system";

//You should create new Page from UI-Editor and extend with it.
export default class Sample extends PageSampleDesign {
myButton: Button;
constructor(private router?: Router, private route?: Route) {
super({});
}

// The page design has been made from the code for better
// showcase purposes. As a best practice, remove this and
// use WYSIWYG editor to style your pages.
centerizeTheChildrenLayout() {
this.dispatch({
type: "updateUserStyle",
userStyle: {
flexProps: {
flexDirection: 'ROW',
justifyContent: 'CENTER',
alignItems: 'CENTER'
}
}
})
}

getContact(contact: Contacts.Contact): void {
const { firstName, phoneNumbers } = contact;
alert("Name : " + firstName + " Phone : " + phoneNumbers);
}

chooseContact(): void {
if (Device.System.OS === System.OSType.ANDROID) {
Permission.android.requestPermissions(Permissions.ANDROID.WRITE_CONTACTS)
.then((e) => {
this.pickContact();
})
.then((reason) => {
console.info("Permission rejected");
});
} else if (Device.System.OS === System.OSType.IOS) {
this.pickContact();
}
}
pickContact() {
//@ts-ignore
Contacts.pickContact({
onSuccess: this.getContact,
page: this,
});
}

onShow() {
super.onShow();
const { headerBar } = this;
Application.statusBar.visible = false;
headerBar.visible = false;

}

onLoad() {
super.onLoad();
this.centerizeTheChildrenLayout();

this.myButton = new Button({
text: "PICK CONTACT",
onPress: (): void => {
this.chooseContact();
},
});

this.addChild(this.myButton, "myButton", ".sf-button", {
marginTop: 250,
marginRight: 50,
marginLeft: 50,
height: 60,
backgroundColor: "#FF0000",
});
}
}