Welcome to the 3. day of the Capacitor Crash Course
Links:
Commands used:
1 |
npm install @capacitor-community/contacts |
Code used in this lesson:
src/app/home/home.page.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
const { Browser, Geolocation, Camera, Contacts } = Plugins; import { Contact } from '@capacitor-community/contacts'; import { isPlatform } from '@ionic/angular'; contacts = []; constructor(private sanitizer: DomSanitizer, private openNativeSettings: OpenNativeSettings) { this.getCurrentPosition(); this.loadContacts(); } async loadContacts() { if (isPlatform('android')) { let permission = await Contacts.getPermissions(); if (!permission.granted) { return; } } Contacts.getContacts().then(result => { console.log(result); this.contacts = result.contacts; }); } |
src/app/home/home.page.html
1 2 3 4 5 6 7 8 9 |
<ion-list> <ion-item *ngFor="let c of contacts"> <ion-label>{{ c.displayName }} <p> {{ c.phoneNumbers[0] }} </p> </ion-label> </ion-item> </ion-list> |