Add to Contact Crashes IOS


#1

when i try to add a contact on my iphone(IOS), the app crashes without showing any error.

Here is my snippet:

contactCrew(crew: Crew) {
let numberSection = [];
this.contacts
.find([“displayName”], {
filter: crew.getName(),
multiple: true,
hasPhoneNumber:false
})
.then(() => {
let contact: Contact = this.contacts.create();
contact.displayName = crew.getName();
let field;
if (crew.getMobile() != null) {
field = new ContactField();
field.type = “Mobile”;
field.value = crew.getMobile();
numberSection.push(field);
}
if (crew.getAlternateMobile() != null) {
field = new ContactField();
field.type = “Alternate Mobile”;
field.value = crew.getAlternateMobile();
numberSection.push(field);
}
if (crew.getFax() != null) {
field = new ContactField();
field.type = “Fax”;
field.value = crew.getFax();
numberSection.push(field);
}
if (crew.getEmail() != null) {
field = new ContactField();
field.type = “Email Id”;
field.value = crew.getEmail();
numberSection.push(field);
}
contact.phoneNumbers = numberSection;
contact.save().then(
(res: any) => {
let toast = this.toastCtrl.create({
message: crew.getName() + '‘s contact has been saved’,
duration: 1500,
}).present();
},
(error: any) => {
console.log(error);
}
);
});
}


#2

Add this to your config.xml under ios platform.

need contacts access to search friends

and remove the whole *-Info.plist key from platform/ios/ios.json and run ionic cordova prepare ios

Reference Link:
https://github.com/apache/cordova-plugin-contacts#ios-quirks
https://stackoverflow.com/questions/47404622/edit-config-for-ios-usage-descriptions-doc-find-is-not-a-function#comment85141465_48182065