Panduan
Cara menggunakan Contacts di Capacitor
Menggunakan @capgo/capacitor-contacts
Antarmuka plugin Contacts Capacitor untuk mengelola kontak perangkat.
Instal
bun add @capgo/capacitor-contacts
bunx cap sync
bunx cap sync menyalin code native plugin ke dalam proyek native Anda. Jalankan kembali setiap kali melakukan upgrade plugin.
Impor
import { CapacitorContacts } from '@capgo/capacitor-contacts';
Sekilas tentang API
| Metode | Deskripsi |
|---|---|
countContacts |
Hitung total jumlah kontak di perangkat. |
createContact |
Buat kontak baru secara programatik. |
createGroup |
Buat grup kontak baru. |
deleteContactById |
Hapus kontak berdasarkan ID. |
deleteGroupById |
Hapus grup berdasarkan ID. |
displayContactById |
Tampilkan kontak menggunakan native contact viewer. |
displayCreateContact |
Tampilkan UI native untuk membuat kontak. |
displayUpdateContactById |
Tampilkan UI update kontak native untuk kontak tertentu. |
getAccounts |
Dapatkan semua akun yang tersedia di perangkat. |
getContactById |
Ambil kontak spesifik berdasarkan ID. |
getContacts |
Ambil semua kontak dari perangkat. |
getGroupById |
Ambil grup spesifik berdasarkan ID. |
getGroups |
Ambil semua grup kontak. |
isAvailable |
Cek apakah kontak tersedia di perangkat. |
isSupported |
Cek apakah plugin didukung di platform saat ini. |
openSettings |
Buka pengaturan kontak di perangkat. |
pickContact |
Pilih satu kontak menggunakan pemilih kontak native. |
pickContacts |
Pilih satu atau lebih kontak menggunakan pemilih kontak native. |
updateContactById |
Update kontak yang ada berdasarkan ID. |
checkPermissions |
Cek status izin akses kontak saat ini. |
requestPermissions |
Minta izin untuk mengakses kontak. |
Contoh
countContacts()
Hitung total jumlah kontak di perangkat.
import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.countContacts();
console.log(result);
createContact()
Buat kontak baru secara programatik.
import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.createContact({ contact: {} });
console.log(result);
createGroup()
Buat grup kontak baru.
import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.createGroup({ group: { name: 'example' } });
console.log(result);
deleteContactById()
Hapus kontak berdasarkan ID.
import { CapacitorContacts } from '@capgo/capacitor-contacts';
await CapacitorContacts.deleteContactById({ id: 'id-123' });
deleteGroupById()
Hapus grup berdasarkan ID.
import { CapacitorContacts } from '@capgo/capacitor-contacts';
await CapacitorContacts.deleteGroupById({ id: 'id-123' });
displayContactById()
Tampilkan kontak menggunakan native contact viewer.
import { CapacitorContacts } from '@capgo/capacitor-contacts';
await CapacitorContacts.displayContactById({ id: 'id-123' });
Tabel di atas mencantumkan 21 metode inti. Listener, helper versi, dan kontrak lengkap setiap metode didokumentasikan di repositori GitHub.
Referensi lengkap
Lanjutkan dari Menggunakan @capgo/capacitor-contacts
Jika Anda menggunakan Menggunakan @capgo/capacitor-contacts untuk merencanakan operasi dashboard dan API, hubungkan dengan @capgo/capacitor-contacts untuk detail implementasi di @capgo/capacitor-contacts, Panduan Memulai untuk detail implementasi di Getting Started, Ringkasan API untuk detail implementasi di API Overview, Pendahuluan untuk detail implementasi di Introduction, dan Kunci API untuk detail implementasi di API Keys.