我有以下代码:
import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { Screenshot } from '@ionic-native/screenshot';
import { AlertController, ToastController } from 'ionic-angular';
import { Contacts } from "@ionic-native/contacts";
import { SMS } from "@ionic-native/sms";
@Component({
selector: 'page-item-details',
templateUrl: 'item-details.html'
})
export class ItemDetailsPage {
selectedItem: any;
screen: any;
state: boolean = false;
alert:AlertController;
contactList: Contacts;
message: SMS;
constructor(private toastCtrl: ToastController, private sms: SMS, public alertCtrl: AlertController, private contacts: Contacts ,public navCtrl: NavController, public navParams: NavParams,private screenshot: Screenshot) {
this.selectedItem = navParams.get('data');
this.alert = alertCtrl;
this.message = sms;
this.contactList = contacts;
}
sendToContact() {
if (this.selectedItem['links'][0]['href'] != null) {
this.contactList.pickContact().then((contact) => {
this.message.send('phonexxxxxx',
this.selectedItem['links'][0]['href'] +" Hey! Checkout this cool product listing on xxxx.com"
,).then((result) => {
let successToast = this.toastCtrl.create({
message: "Text message sent successfully! :)",
duration: 3000
})
successToast.present();
}, (error) => {
let errorToast = this.toastCtrl.create({
message: "Text message not sent. :(",
duration: 3000
})
errorToast.present();
});
},()=>{
console.log("rejected");
});
}
}
}
如何获取用户的电话号码?我可以转到联系人列表并返回选定的联系人。如何在该对象中导航?我相信它给了我一个电话号码清单。我只想要一个,或者让用户选择是否多个。
答案 0 :(得分:2)
获取联系人对象后,使用 contact.phoneNumbers [0] .value 来获取第一个电话号码。