addContact(): void {
alert('addContact invoked');
let contact: Contact = this.contacts.create();
contact.name = new ContactName('', 'Smith', 'John');
let number = new ContactField('mobile', '6471234567');
contact.phoneNumbers = [number];
alert('contact created + ' + contact.name + ' ' + contact.phoneNumbers);
contact.save().then(
() => alert('Contact saved!' + contact),
(error: any) => alert('Error saving contact.' + error)
).catch(error => {
alert('error occurred while adding contact')
});
alert('Contact should be saved');
}
nothing happens, alert is not invoked in (then)
Contact is not saved, same goes with contacts.find()
I assume you are testing on device and have set the permissions correctly in the config.xml to allow access to the contacts?
Hi.Yes , please assume that permissions are set OK and plugin is installed according to the documentation. Although, inspecting it from browser, with connected device , I get:
Native: tried calling Contacts.create, but the Contacts plugin is not installed.
Yes,Ionic Native modules into app.module.ts file and included them in the provider array
Please find related info to this:
config.xml
<plugin name="cordova-plugin-contacts" spec="3.0.1" />
package.json
"cordova-plugin-contacts": "3.0.1",
"@ionic-native/contacts": "^5.2.0",
"cordova-plugin-contacts": {},
fixed it by manually deleting node_modules
and ran npm install
again
You will also need to include this in your config.xml if you are targeting iOS:
<platform name="ios">
<config-file parent="NSContactsUsageDescription" target="*info.plist">
<string>MESSAGE TO THE USER</string>
</config-file>
</platform>
thanks Chris. Now i’m focused on Android, but definitely will come back to this