Coder Social home page Coder Social logo

apache / cordova-plugin-contacts Goto Github PK

View Code? Open in Web Editor NEW
213.0 33.0 373.0 912 KB

[DEPRECATED] Apache Cordova Plugin contacts

License: Apache License 2.0

JavaScript 35.16% Java 26.20% Objective-C 24.05% C++ 5.73% C# 8.85%
cordova csharp cplusplus library objective-c java nodejs javascript mobile

cordova-plugin-contacts's Introduction

title description
Contacts
Manage the contacts on the device.
AppVeyor Travis CI
Build status Build Status

cordova-plugin-contacts

This plugin defines a global navigator.contacts object, which provides access to the device contacts database.

Although the object is attached to the global scoped navigator, it is not available until after the deviceready event.

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
console.log(navigator.contacts);
}

⚠️ WARNING: Collection and use of contact data raises important privacy issues. Your app's privacy policy should discuss how the app uses contact data and whether it is shared with any other parties.
Contact information is considered sensitive because it reveals the people with whom a person communicates. Therefore, in addition to the app's privacy policy, you should strongly consider providing a just-in-time notice before the app accesses or uses contact data, if the device operating system doesn't do so already. That notice should provide the same information noted above, as well as obtaining the user's permission (e.g., by presenting choices for OK and No Thanks).
Note that some app marketplaces may require the app to provide a just-in-time notice and obtain the user's permission before accessing contact data. A clear and easy-to-understand user experience surrounding the use of contact data helps avoid user confusion and perceived misuse of contact data.
For more information, please see the Privacy Guide.


Deprecation Notice

This plugin is being deprecated. No more work will be done on this plugin by the Cordova development community. You can continue to use this plugin and it should work as-is in the future but any more arising issues will not be fixed by the Cordova community.


Installation

cordova plugin add cordova-plugin-contacts

Older versions of cordova can still install via the deprecated id (stale v0.2.16)

cordova plugin add org.apache.cordova.contacts

It is also possible to install via repo url directly (unstable)

cordova plugin add https://github.com/apache/cordova-plugin-contacts.git

iOS Quirks

Since iOS 10 it's mandatory to provide an usage description in the info.plist if trying to access privacy-sensitive data. When the system prompts the user to allow access, this usage description string will displayed as part of the permission dialog box, but if you didn't provide the usage description, the app will crash before showing the dialog. Also, Apple will reject apps that access private data but don't provide an usage description.

This plugins requires the following usage description:

  • NSContactsUsageDescription describes the reason that the app accesses the user's contacts.

To add this entry into the info.plist, you can use the edit-config tag in the config.xml like this:

<edit-config target="NSContactsUsageDescription" file="*-Info.plist" mode="merge">
    <string>need contacts access to search friends</string>
</edit-config>

Windows Quirks

Prior to Windows 10: Any contacts returned from find and pickContact methods are readonly, so your application cannot modify them. find method available only on Windows Phone 8.1 devices.

Windows 10 and above: Contacts may be saved and will be saved to app-local contacts storage. Contacts may also be deleted.

deprecated platforms

Firefox OS Quirks

Create www/manifest.webapp as described in Manifest Docs. Add relevant permisions. There is also a need to change the webapp type to "privileged" - Manifest Docs. WARNING: All privileged apps enforce Content Security Policy which forbids inline script. Initialize your application in another way.

"type": "privileged",
"permissions": {
	"contacts": {
		"access": "readwrite",
		"description": "Describe why there is a need for such permission"
	}
}

Windows 8 Quirks

Windows 8 Contacts are readonly. Via the Cordova API Contacts are not queryable/searchable, you should inform the user to pick a contact as a call to contacts.pickContact which will open the 'People' app where the user must choose a contact. Any contacts returned are readonly, so your application cannot modify them.

navigator.contacts

Methods

  • navigator.contacts.create
  • navigator.contacts.find
  • navigator.contacts.pickContact

Objects

  • Contact
  • ContactName
  • ContactField
  • ContactAddress
  • ContactOrganization
  • ContactFindOptions
  • ContactError
  • ContactFieldType

navigator.contacts.create

The navigator.contacts.create method is synchronous, and returns a new Contact object.

This method does not retain the Contact object in the device contacts database, for which you need to invoke the Contact.save method.

Supported Platforms

  • Android
  • BlackBerry 10
  • Firefox OS
  • iOS
  • Windows Phone 8

Example

    var myContact = navigator.contacts.create({"displayName": "Test User"});

navigator.contacts.find

The navigator.contacts.find method executes asynchronously, querying the device contacts database and returning an array of Contact objects. The resulting objects are passed to the contactSuccess callback function specified by the contactSuccess parameter.

The contactFields parameter should always be an array and specifies the fields to be used as a search qualifier. A zero-length contactFields parameter is invalid and results in ContactError.INVALID_ARGUMENT_ERROR. A contactFields value of ["*"] searches all contact fields.

The contactFindOptions.filter string can be used as a search filter when querying the contacts database. If provided, a case-insensitive, partial value match is applied to each field specified in the contactFields parameter. If there's a match for any of the specified fields, the contact is returned. Use contactFindOptions.desiredFields parameter to control which contact properties must be returned back.

Supported values for both contactFields and contactFindOptions.desiredFields parameters are enumerated in ContactFieldType object.

Parameters

  • contactFields: Contact fields to use as a search qualifier. (DOMString[]) [Required]

  • contactSuccess: Success callback function invoked with the array of Contact objects returned from the database. [Required]

  • contactError: Error callback function, invoked when an error occurs. [Optional]

  • contactFindOptions: Search options to filter navigator.contacts. [Optional]

    Keys include:

    • filter: The search string used to find navigator.contacts. (DOMString) (Default: "")

    • multiple: Determines if the find operation returns multiple navigator.contacts. (Boolean) (Default: false)

    • desiredFields: Contact fields to be returned back. If specified, the resulting Contact object only features values for these fields. (DOMString[]) [Optional]

    • hasPhoneNumber(Android only): Filters the search to only return contacts with a phone number informed. (Boolean) (Default: false)

Supported Platforms

  • Android
  • iOS
  • Windows (Windows Phone 8.1 and Windows 10)
  • BlackBerry 10
  • Firefox OS
  • Windows Phone 8

Example

function onSuccess(contacts) {
	alert('Found ' + contacts.length + ' contacts.');
};

function onError(contactError) {
	alert('onError!');
};

// find all contacts with 'Bob' in any name field
var options      = new ContactFindOptions();
options.filter   = "Bob";
options.multiple = true;
options.desiredFields = [navigator.contacts.fieldType.id];
options.hasPhoneNumber = true;
var fields       = [navigator.contacts.fieldType.displayName, navigator.contacts.fieldType.name];
navigator.contacts.find(fields, onSuccess, onError, options);

Windows Quirks

  • contactFields is not supported and will be ignored. find method will always attempt to match the name, email address, or phone number of a contact.

navigator.contacts.pickContact

The navigator.contacts.pickContact method launches the Contact Picker to select a single contact. The resulting object is passed to the contactSuccess callback function specified by the contactSuccess parameter.

Parameters

  • contactSuccess: Success callback function invoked with the single Contact object. [Required]

  • contactError: Error callback function, invoked when an error occurs. [Optional]

Supported Platforms

  • Android
  • iOS
  • Windows
  • Windows Phone 8

Example

navigator.contacts.pickContact(function(contact){
        console.log('The following contact has been selected:' + JSON.stringify(contact));
    },function(err){
        console.log('Error: ' + err);
    });

Android Quirks

This plugin launches an external Activity for picking contacts. See the Android Lifecycle Guide for an explanation of how this affects your application. If the plugin returns its result in the resume event, then you must first wrap the returned object in a Contact object before using it. Here is an example:

function onResume(resumeEvent) {
    if(resumeEvent.pendingResult) {
        if(resumeEvent.pendingResult.pluginStatus === "OK") {
            var contact = navigator.contacts.create(resumeEvent.pendingResult.result);
            successCallback(contact);
        } else {
            failCallback(resumeEvent.pendingResult.result);
        }
    }
}

Contact

The Contact object represents a user's contact. Contacts can be created, stored, or removed from the device contacts database. Contacts can also be retrieved (individually or in bulk) from the database by invoking the navigator.contacts.find method.

NOTE: Not all of the contact fields listed above are supported on every device platform. Please check each platform's Quirks section for details.

Properties

  • id: A globally unique identifier. (DOMString)

  • displayName: The name of this Contact, suitable for display to end users. (DOMString)

  • name: An object containing all components of a persons name. (ContactName)

  • nickname: A casual name by which to address the contact. (DOMString)

  • phoneNumbers: An array of all the contact's phone numbers. (ContactField[])

  • emails: An array of all the contact's email addresses. (ContactField[])

  • addresses: An array of all the contact's addresses. (ContactAddress[])

  • ims: An array of all the contact's IM addresses. (ContactField[])

  • organizations: An array of all the contact's organizations. (ContactOrganization[])

  • birthday: The birthday of the contact. (Date)

  • note: A note about the contact. (DOMString)

  • photos: An array of the contact's photos. (ContactField[])

  • categories: An array of all the user-defined categories associated with the contact. (ContactField[])

  • urls: An array of web pages associated with the contact. (ContactField[])

Methods

  • clone: Returns a new Contact object that is a deep copy of the calling object, with the id property set to null.

  • remove: Removes the contact from the device contacts database, otherwise executes an error callback with a ContactError object.

  • save: Saves a new contact to the device contacts database, or updates an existing contact if a contact with the same id already exists.

Supported Platforms

  • Android
  • iOS
  • Windows
  • BlackBerry 10
  • Firefox OS
  • Amazon Fire OS
  • Windows Phone 8

Save Example

function onSuccess(contact) {
    alert("Save Success");
};

function onError(contactError) {
    alert("Error = " + contactError.code);
};

// create a new contact object
var contact = navigator.contacts.create();
contact.displayName = "Plumber";
contact.nickname = "Plumber";            // specify both to support all devices

// populate some fields
var name = new ContactName();
name.givenName = "Jane";
name.familyName = "Doe";
contact.name = name;

// save to device
contact.save(onSuccess,onError);

Clone Example

// clone the contact object
var clone = contact.clone();
clone.name.givenName = "John";
console.log("Original contact name = " + contact.name.givenName);
console.log("Cloned contact name = " + clone.name.givenName);

Remove Example

function onSuccess() {
    alert("Removal Success");
};

function onError(contactError) {
    alert("Error = " + contactError.code);
};

// remove the contact from the device
contact.remove(onSuccess,onError);

Removing phone number(s) from a saved contact

// Example to create a contact with 3 phone numbers and then remove
// 2 phone numbers. This example is for illustrative purpose only
var myContact = navigator.contacts.create({"displayName": "Test User"});
var phoneNumbers = [];

phoneNumbers[0] = new ContactField('work', '768-555-1234', false);
phoneNumbers[1] = new ContactField('mobile', '999-555-5432', true); // preferred number
phoneNumbers[2] = new ContactField('home', '203-555-7890', false);

myContact.phoneNumbers = phoneNumbers;
myContact.save(function (contact_obj) {
    var contactObjToModify = contact_obj.clone();
    contact_obj.remove(function(){
        var phoneNumbers = [contactObjToModify.phoneNumbers[0]];
        contactObjToModify.phoneNumbers = phoneNumbers;
        contactObjToModify.save(function(c_obj){
            console.log("All Done");
        }, function(error){
            console.log("Not able to save the cloned object: " + error);
        });
    }, function(contactError) {
        console.log("Contact Remove Operation failed: " + contactError);
    });
});

iOS Quirks

  • displayName: Not supported on iOS, returning null unless there is no ContactName specified, in which case it returns the composite name, nickname or "", respectively.

  • birthday: Must be input as a JavaScript Date object, the same way it is returned.

  • photos: Returns a File URL to the image, which is stored in the application's temporary directory. Contents of the temporary directory are removed when the application exits.

  • categories: This property is currently not supported, returning null.

Android 2.X Quirks

  • categories: Not supported on Android 2.X devices, returning null.

Windows Quirks

  • photos: Returns a File URL to the image, which is stored in the application's temporary directory.

  • birthdays: Not supported, returning null.

  • categories: Not supported, returning null.

  • remove: Method is only supported in Windows 10 or above.

deprecated platforms

BlackBerry 10 Quirks

  • id: Assigned by the device when saving the contact.

FirefoxOS Quirks

  • categories: Partially supported. Fields pref and type are returning null

  • ims: Not supported

  • photos: Not supported

Windows Phone 8 Quirks

  • displayName: When creating a contact, the value provided for the display name parameter differs from the display name retrieved when finding the contact.

  • urls: When creating a contact, users can input and save more than one web address, but only one is available when searching the contact.

  • phoneNumbers: The pref option is not supported. The type is not supported in a find operation. Only one phoneNumber is allowed for each type.

  • emails: The pref option is not supported. Home and personal references same email entry. Only one entry is allowed for each type.

  • addresses: Supports only work, and home/personal type. The home and personal type reference the same address entry. Only one entry is allowed for each type.

  • organizations: Only one is allowed, and does not support the pref, type, and department attributes.

  • note: Not supported, returning null.

  • ims: Not supported, returning null.

  • birthdays: Not supported, returning null.

  • categories: Not supported, returning null.

  • remove: Method is not supported

ContactAddress

The ContactAddress object stores the properties of a single address of a contact. A Contact object may include more than one address in a ContactAddress[] array.

Properties

  • pref: Set to true if this ContactAddress contains the user's preferred value. (boolean)

  • type: A string indicating what type of field this is, home for example. (DOMString)

  • formatted: The full address formatted for display. (DOMString)

  • streetAddress: The full street address. (DOMString)

  • locality: The city or locality. (DOMString)

  • region: The state or region. (DOMString)

  • postalCode: The zip code or postal code. (DOMString)

  • country: The country name. (DOMString)

Supported Platforms

  • Android
  • iOS
  • Windows
  • Amazon Fire OS
  • BlackBerry 10
  • Firefox OS
  • Windows Phone 8

Example

// display the address information for all contacts

function onSuccess(contacts) {
    for (var i = 0; i < contacts.length; i++) {
        for (var j = 0; j < contacts[i].addresses.length; j++) {
            alert("Pref: "         + contacts[i].addresses[j].pref          + "\n" +
                "Type: "           + contacts[i].addresses[j].type          + "\n" +
                "Formatted: "      + contacts[i].addresses[j].formatted     + "\n" +
                "Street Address: " + contacts[i].addresses[j].streetAddress + "\n" +
                "Locality: "       + contacts[i].addresses[j].locality      + "\n" +
                "Region: "         + contacts[i].addresses[j].region        + "\n" +
                "Postal Code: "    + contacts[i].addresses[j].postalCode    + "\n" +
                "Country: "        + contacts[i].addresses[j].country);
        }
    }
};

function onError(contactError) {
    alert('onError!');
};

// find all contacts
var options = new ContactFindOptions();
options.filter = "";
options.multiple = true;
var filter = ["displayName", "addresses"];
navigator.contacts.find(filter, onSuccess, onError, options);

iOS Quirks

  • pref: Not supported on iOS devices, returning false.

  • formatted: Currently not supported.

Windows Quirks

  • pref: Not supported

Android 2.X Quirks

  • pref: Not supported, returning false on Android 2.X devices.
deprecated platforms

BlackBerry 10 Quirks

  • pref: Not supported on BlackBerry devices, returning false.

  • type: Partially supported. Only one each of Work and Home type addresses can be stored per contact.

  • formatted: Partially supported. Returns a concatenation of all BlackBerry address fields.

  • streetAddress: Supported. Returns a concatenation of BlackBerry address1 and address2 address fields.

  • locality: Supported. Stored in BlackBerry city address field.

  • region: Supported. Stored in BlackBerry stateProvince address field.

  • postalCode: Supported. Stored in BlackBerry zipPostal address field.

  • country: Supported.

FirefoxOS Quirks

  • formatted: Currently not supported

ContactError

The ContactError object is returned to the user through the contactError callback function when an error occurs.

Properties

  • code: One of the predefined error codes listed below.

Constants

  • ContactError.UNKNOWN_ERROR (code 0)
  • ContactError.INVALID_ARGUMENT_ERROR (code 1)
  • ContactError.TIMEOUT_ERROR (code 2)
  • ContactError.PENDING_OPERATION_ERROR (code 3)
  • ContactError.IO_ERROR (code 4)
  • ContactError.NOT_SUPPORTED_ERROR (code 5)
  • ContactError.OPERATION_CANCELLED_ERROR (code 6)
  • ContactError.PERMISSION_DENIED_ERROR (code 20)

ContactField

The ContactField object is a reusable component that represents contact fields generically. Each ContactField object contains a value, type, and pref property. A Contact object stores several properties in ContactField[] arrays, such as phone numbers and email addresses.

In most instances, there are no pre-determined values for a ContactField object's type attribute. For example, a phone number can specify type values of home, work, mobile, iPhone, or any other value that is supported by a particular device platform's contact database. However, for the Contact photos field, the type field indicates the format of the returned image: url when the value attribute contains a URL to the photo image, or base64 when the value contains a base64-encoded image string.

Properties

  • type: A string that indicates what type of field this is, home for example. (DOMString)

  • value: The value of the field, such as a phone number or email address. (DOMString)

  • pref: Set to true if this ContactField contains the user's preferred value. (boolean)

Supported Platforms

  • Android
  • iOS
  • Windows
  • BlackBerry 10
  • Firefox OS
  • Amazon Fire OS
  • Windows Phone 8

Example

// create a new contact
var contact = navigator.contacts.create();

// store contact phone numbers in ContactField[]
var phoneNumbers = [];
phoneNumbers[0] = new ContactField('work', '212-555-1234', false);
phoneNumbers[1] = new ContactField('mobile', '917-555-5432', true); // preferred number
phoneNumbers[2] = new ContactField('home', '203-555-7890', false);
contact.phoneNumbers = phoneNumbers;

// save the contact
contact.save();

iOS Quirks

  • pref: Not supported, returning false.

Windows Quirks

  • pref: Not supported, returning false.

Android Quirks

  • pref: Not supported, returning false.
deprecated platforms

BlackBerry 10 Quirks

  • type: Partially supported. Used for phone numbers.

  • value: Supported.

  • pref: Not supported, returning false.

ContactName

Contains different kinds of information about a Contact object's name.

Properties

  • formatted: The complete name of the contact. (DOMString)

  • familyName: The contact's family name. (DOMString)

  • givenName: The contact's given name. (DOMString)

  • middleName: The contact's middle name. (DOMString)

  • honorificPrefix: The contact's prefix (example Mr. or Dr.) (DOMString)

  • honorificSuffix: The contact's suffix (example Esq.). (DOMString)

Supported Platforms

  • Android
  • iOS
  • Windows
  • BlackBerry 10
  • Firefox OS
  • Amazon Fire OS
  • Windows Phone 8

Example

function onSuccess(contacts) {
    for (var i = 0; i < contacts.length; i++) {
        alert("Formatted: "  + contacts[i].name.formatted       + "\n" +
            "Family Name: "  + contacts[i].name.familyName      + "\n" +
            "Given Name: "   + contacts[i].name.givenName       + "\n" +
            "Middle Name: "  + contacts[i].name.middleName      + "\n" +
            "Suffix: "       + contacts[i].name.honorificSuffix + "\n" +
            "Prefix: "       + contacts[i].name.honorificSuffix);
    }
};

function onError(contactError) {
    alert('onError!');
};

var options = new ContactFindOptions();
options.filter = "";
options.multiple = true;
filter = ["displayName", "name"];
navigator.contacts.find(filter, onSuccess, onError, options);

Android Quirks

  • formatted: Partially supported, and read-only. Returns a concatenation of honorificPrefix, givenName, middleName, familyName, and honorificSuffix.

iOS Quirks

  • formatted: Partially supported. Returns iOS Composite Name, but is read-only.

Windows Quirks

  • formatted: This is the only name property, and is identical to displayName, and nickname

  • familyName: not supported

  • givenName: not supported

  • middleName: not supported

  • honorificPrefix: not supported

  • honorificSuffix: not supported

deprecated platforms

BlackBerry 10 Quirks

  • formatted: Partially supported. Returns a concatenation of BlackBerry firstName and lastName fields.

  • familyName: Supported. Stored in BlackBerry lastName field.

  • givenName: Supported. Stored in BlackBerry firstName field.

  • middleName: Not supported, returning null.

  • honorificPrefix: Not supported, returning null.

  • honorificSuffix: Not supported, returning null.

FirefoxOS Quirks

  • formatted: Partially supported, and read-only. Returns a concatenation of honorificPrefix, givenName, middleName, familyName, and honorificSuffix.

ContactOrganization

The ContactOrganization object stores a contact's organization properties. A Contact object stores one or more ContactOrganization objects in an array.

Properties

  • pref: Set to true if this ContactOrganization contains the user's preferred value. (boolean)

  • type: A string that indicates what type of field this is, home for example. _(DOMString)

  • name: The name of the organization. (DOMString)

  • department: The department the contract works for. (DOMString)

  • title: The contact's title at the organization. (DOMString)

Supported Platforms

  • Android
  • iOS
  • Windows (Windows 8.1 and Windows Phone 8.1 devices only)
  • BlackBerry 10
  • Firefox OS
  • Windows Phone 8

Example

function onSuccess(contacts) {
    for (var i = 0; i < contacts.length; i++) {
        for (var j = 0; j < contacts[i].organizations.length; j++) {
            alert("Pref: "      + contacts[i].organizations[j].pref       + "\n" +
                "Type: "        + contacts[i].organizations[j].type       + "\n" +
                "Name: "        + contacts[i].organizations[j].name       + "\n" +
                "Department: "  + contacts[i].organizations[j].department + "\n" +
                "Title: "       + contacts[i].organizations[j].title);
        }
    }
};

function onError(contactError) {
    alert('onError!');
};

var options = new ContactFindOptions();
options.filter = "";
options.multiple = true;
filter = ["displayName", "organizations"];
navigator.contacts.find(filter, onSuccess, onError, options);

iOS Quirks

  • pref: Not supported on iOS devices, returning false.

  • type: Not supported on iOS devices, returning null.

  • name: Partially supported. The first organization name is stored in the iOS kABPersonOrganizationProperty field.

  • department: Partially supported. The first department name is stored in the iOS kABPersonDepartmentProperty field.

  • title: Partially supported. The first title is stored in the iOS kABPersonJobTitleProperty field.

Windows Quirks

  • pref: Not supported, returning false.

  • type: Not supported, returning null.

Android 2.X Quirks

  • pref: Not supported by Android 2.X devices, returning false.
deprecated platforms

BlackBerry 10 Quirks

  • pref: Not supported by BlackBerry devices, returning false.

  • type: Not supported by BlackBerry devices, returning null.

  • name: Partially supported. The first organization name is stored in the BlackBerry company field.

  • department: Not supported, returning null.

  • title: Partially supported. The first organization title is stored in the BlackBerry jobTitle field.

Firefox OS Quirks

  • pref: Not supported

  • type: Not supported

  • department: Not supported

  • Fields name and title stored in org and jobTitle.

ContactFieldType

The ContactFieldType object is an enumeration of possible field types, such as 'phoneNumbers' or 'emails', that could be used to control which contact properties must be returned back from contacts.find() method (see contactFindOptions.desiredFields), or to specify fields to search in (through contactFields parameter). Possible values are:

  • navigator.contacts.fieldType.addresses
  • navigator.contacts.fieldType.birthday
  • navigator.contacts.fieldType.categories
  • navigator.contacts.fieldType.country
  • navigator.contacts.fieldType.department
  • navigator.contacts.fieldType.displayName
  • navigator.contacts.fieldType.emails
  • navigator.contacts.fieldType.familyName
  • navigator.contacts.fieldType.formatted
  • navigator.contacts.fieldType.givenName
  • navigator.contacts.fieldType.honorificPrefix
  • navigator.contacts.fieldType.honorificSuffix
  • navigator.contacts.fieldType.id
  • navigator.contacts.fieldType.ims
  • navigator.contacts.fieldType.locality
  • navigator.contacts.fieldType.middleName
  • navigator.contacts.fieldType.name
  • navigator.contacts.fieldType.nickname
  • navigator.contacts.fieldType.note
  • navigator.contacts.fieldType.organizations
  • navigator.contacts.fieldType.phoneNumbers
  • navigator.contacts.fieldType.photos
  • navigator.contacts.fieldType.postalCode
  • navigator.contacts.fieldType.region
  • navigator.contacts.fieldType.streetAddress
  • navigator.contacts.fieldType.title
  • navigator.contacts.fieldType.urls

cordova-plugin-contacts's People

Contributors

agrieve avatar alsorokin avatar baboring avatar bennmapes avatar clelland avatar cmarcelk avatar dblotsky avatar filmaj avatar hardeep avatar infil00p avatar jamesjong avatar janpio avatar jcesarmobile avatar jonmikelm avatar ldeluca avatar macdonst avatar matrosov-nikita avatar mmocny avatar nikhilkh avatar omefire avatar purplecabbage avatar riknoll avatar sarangan12 avatar sgrebnov avatar shazron avatar stacic avatar stevengill avatar timkim avatar vladimir-kotikov avatar zalun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cordova-plugin-contacts's Issues

URL ignored during contact save

Im trying to save a contact which works for most information but if I try to add an URL to the contact it just ignores the update without an error.

For example:

contact.urls.push(new ContactField("SomeValue", "http://www.example.com"))
console.log(contact)
let result = await contact.save()
console.log(result)

Print before save():
... "urls":[{"type":"SomeValue","value":"http://www.example.com"}] ...
After contact.save():
... "urls":null ...

Any idea why my input is ignored?

Deprecation notices iOS 9

I was wondering what happens if Apple forces users to use the newer SDK from XCode 10. Do we still get these deprecation notices or cant we use this existing plugin anymore starting from Match?

App Crash with iOS 14

Bug Report

Problem

The app crashes after the permissions window appears and you click "allow." If you re-open the app, the permission is granted and you can access the contacts correctly. Has anyone else seen this or know any fixes/forks that address this?

What is expected to happen?

The app will not crash after allowing contact permissions.

What does actually happen?

It crashes.

Information

I have set the NSContactsUsageDescription in Info.plist and see that when it prompts so I know that isn't the problem. From debugging the crash log there is an error that says:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Call must be made on main thread'

I suspect this is a problem with the way the plugin is implemented not using the main thread

Command or Code

The pickContact method being called for the first time in an app, causing the permissions window to appear. After accepting you should see the crash.

Environment, Platform, Device

All iOS devices on version 14 (could have been happening earlier but I didn't notice it).

Version information

Cordova 10, cordova-plugin-contacts 3.0.1 (latest)

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Add hash with all contact list

Now I have a problem to define whether the contacts have been updated or created. I wanted to implement the functionality of getting the updated date of the contacts in order to define whether some of the contacts has been changed. As now the Android is not giving the possibility to get the created and updated date we decided to generate hash with contact list data. So in app we can compare between the hash received from plugin and the hash received before that. By using this functionality we can understand if the contact list have been changed.

Not working when there are more than one contacts apps

We have a Samsung Galaxy S9 and it has two contacts apps. It lets us choose which app, then it shows the list of contacts, but when we select a contact, the result is "OPERATION_CANCELLED_ERROR".

More specifically, the second app is the app "Drupe". If we select a default contacts app, everything works fine.

modify the contact picture

Feature Request

Motivation Behind Feature

As we are creating the phone contact manger module, we want to set users profile picture.

Feature Description

As currently we are able to store all users details but we are not able to store the contact photo, my code is as follows:

contact.photos= [new ContactField('photo', this.tempProfilepic)];
where tempProfilePic is filePath URL, also I tried with base64 as well but nothing worked,
Might be the solution already available but I am not able to find it out properly.

Thanks in advance.

Alternatives or Workarounds

Not allowed to load local resource

Not able to get the image to work, receive below error in chrome debug:
Not allowed to load local resource : content://com.android.contacts/contacts/8/photo

also tried application here but no success, https://github.com/janpio/ionic-native-contacts

also noticed someone had same issue but got resolved by removing the webview plugin, But I require that plugin #165

code:

   getContacts() {
    this.contacts.find(
      ["displayName", "phoneNumbers","photos"],
      {multiple: true, hasPhoneNumber: true}
      ).then((contacts) => {
        for (var i=0 ; i < contacts.length; i++){
          if(contacts[i].displayName !== null) {
            var contact = {};
            contact["name"]   = contacts[i].displayName;
            contact["number"] = contacts[i].phoneNumbers[0].value;
            if(contacts[i].photos != null) {
              console.log(contacts[i].photos);
              contact["image"] = this.sanitizer.bypassSecurityTrustUrl(contacts[i].photos[0].value);
              console.log(contact);
            } else {
              contact["image"] = "assets/dummy-profile-pic.png";
            }
            this.contactList.push(contact);
          }
        }
    });
  }

my ionic info:

$ ionic info
✔ Gathering environment info - done!

Ionic:

   ionic (Ionic CLI)             : 4.2.1 (/usr/local/lib/node_modules/ionic)
   Ionic Framework               : @ionic/angular 4.0.0-beta.13
   @angular-devkit/build-angular : 0.8.6
   @angular-devkit/schematics    : 0.8.6
   @angular/cli                  : 6.2.6
   @ionic/angular-toolkit        : 1.0.0

Cordova:

   cordova (Cordova CLI) : 8.0.0
   Cordova Platforms     : android 7.0.0
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 2.2.0, (and 10 other plugins)

System:

   Android SDK Tools : 26.1.1 (/Users/me/Library/Android/sdk)
   ios-deploy        : 1.9.4
   ios-sim           : 7.0.0
   NodeJS            : v8.11.3 (/usr/local/bin/node)
   npm               : 6.3.0
   OS                : macOS
   Xcode             : Xcode 10.0 Build version 10A255

and package.json

{
  "name": "test",
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "http://ionicframework.com/",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "~6.1.1",
    "@angular/core": "~6.1.1",
    "@angular/forms": "~6.1.1",
    "@angular/http": "~6.1.1",
    "@angular/platform-browser": "~6.1.1",
    "@angular/platform-browser-dynamic": "~6.1.1",
    "@angular/router": "~6.1.1",
    "@ionic-native/base64": "^5.0.0-beta.21",
    "@ionic-native/camera": "^5.0.0-beta.21",
    "@ionic-native/contacts": "^5.0.0-beta.21",
    "@ionic-native/core": "5.0.0-beta.21",
    "@ionic-native/diagnostic": "^5.0.0-beta.21",
    "@ionic-native/fcm": "^5.0.0-beta.21",
    "@ionic-native/ionic-webview": "^5.0.0-beta.21",
    "@ionic-native/native-storage": "^5.0.0-beta.21",
    "@ionic-native/network": "^5.0.0-beta.21",
    "@ionic-native/splash-screen": "5.0.0-beta.21",
    "@ionic-native/sqlite": "^5.0.0-beta.21",
    "@ionic-native/status-bar": "5.0.0-beta.21",
    "@ionic/angular": "4.0.0-beta.13",
    "@ionic/pro": "2.0.3",
    "com-badrit-base64": "^0.2.0",
    "cordova-android": "7.0.0",
    "cordova-plugin-camera": "^4.0.3",
    "cordova-plugin-contacts": "^3.0.1",
    "cordova-plugin-device": "^2.0.2",
    "cordova-plugin-fcm-with-dependecy-updated": "^2.2.6",
    "cordova-plugin-ionic-keyboard": "^2.1.3",
    "cordova-plugin-ionic-webview": "^2.2.0",
    "cordova-plugin-nativestorage": "^2.3.2",
    "cordova-plugin-network-information": "^2.0.1",
    "cordova-plugin-splashscreen": "^5.0.2",
    "cordova-plugin-statusbar": "^2.4.2",
    "cordova-plugin-whitelist": "^1.3.3",
    "cordova-sqlite-storage": "^2.5.0",
    "cordova.plugins.diagnostic": "^4.0.10",
    "core-js": "^2.5.3",
    "rxjs": "6.2.2",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/architect": "~0.8.5",
    "@angular-devkit/build-angular": "~0.8.5",
    "@angular-devkit/core": "~0.8.5",
    "@angular-devkit/schematics": "~0.8.5",
    "@angular/cli": "~6.2.5",
    "@angular/compiler": "~6.1.1",
    "@angular/compiler-cli": "~6.1.1",
    "@angular/language-service": "~6.1.1",
    "@ionic/angular-toolkit": "^1.0.0",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~10.12.0",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~3.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.0",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~2.9.2"
  },
  "description": "An Ionic project",
  "cordova": {
    "plugins": {
      "cordova-plugin-contacts": {},
      "cordova-plugin-camera": {},
      "cordova-plugin-fcm-with-dependecy-updated": {},
      "cordova-plugin-nativestorage": {},
      "cordova-plugin-network-information": {},
      "cordova-sqlite-storage": {},
      "cordova-plugin-whitelist": {},
      "cordova-plugin-statusbar": {},
      "cordova-plugin-device": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-ionic-keyboard": {},
      "cordova.plugins.diagnostic": {},
      "com-badrit-base64": {},
      "cordova-plugin-ionic-webview": {}
    },
    "platforms": [
      "android"
    ]
  }
}

App crashed

This plugin crashed app android version 8 but contact is save correctly.

conduct contact.save() twice on Android, but only get one contact.

Bug Report

Problem

I conduct contact.save() twice on android.
contact1 and contact2 are the same expect that they have different comany name.

What is expected to happen?

I expect to get two contact on my phone, which is contact1 and contact2.

What does actually happen?

I only get contact1 on my phone.
But on IOS, I actually get two contacts.

I am using cordova-plugin-contacts of version "2.3.1"

Can someone help?

App flashes when authorized to read contacts ?

java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.ContactsProvider2 from ProcessRecord{1daa3c0 5625:{packname}/u0a508} (pid=5625, uid=10508) requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS
	at android.os.Parcel.readException(Parcel.java:1684)
	at android.os.Parcel.readException(Parcel.java:1637)
	at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:4287)
	at android.app.ActivityThread.acquireProvider(ActivityThread.java:5672)
	at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2278)
	at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1533)
	at android.content.ContentResolver.query(ContentResolver.java:518)
	at android.content.ContentResolver.query(ContentResolver.java:475)
	at org.apache.cordova.contacts.ContactAccessorSdk5.search(ContactAccessorSdk5.java:196)
	at org.apache.cordova.contacts.ContactManager$3.run(ContactManager.java:209)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
	at java.lang.Thread.run(Thread.java:760)

Some people say that it is a sdk problem, there are corresponding programs, but I will not develop Android, so I can't understand how to modify it.

This problem occurs in the miui system, which is the Chinese Android custom system for Xiaomi.

The following is the corresponding solution I found, but after the tutorial is modified, the compiler package will report an error, I think there is a problem with the method or what jar package is missing.
https://blog.csdn.net/OREO_GO/article/details/52295099
https://blog.csdn.net/waww116529/article/details/77719531

Contact updates of the arrays (phoneNumbers, addresses, urls) ignored on iOS

I tried updating contact information on iOS using the plugin and it worked for strings but once I tried to modify array types, it was actually just ignored in the update.
After searching a bit further, I noticed that when I did put a breakpoint in the ios code, it worked but when removing that breakpoint again, it failed. Which made me conclude that its some kind of race condition.
Now I wonder if this issue is Ionic related or not. Not that Ionic does a lot with the contacts itself, it basically just allows Typescripting etc.

Anyone using this plugin with Ionic which notices the same issues?

App Crash after save the new contact in Android 9

When I try to save the new contact in Android 9, the App crash always after insert the contact. There is permissions for READ and WRITE in AndroidManifest.xml

Here, the code:

var myContact = navigator.contacts.create({
      displayName: 'Test',
       phoneNumbers: [{
              'type'  : 'phone',
              'value' : '99999999'
       }],
        emails: [{
              'type': 'email',
              'value': '[email protected]'
       }]
}); 
myContact.save();

The code is very simple and save the contact perfectly in my Android phone, but the problem is that the App Crash after save.

Anyone know what the problem may be and could you help me ??

Thanks.

NullInjectorError: No provider for Contacts!

Bug Report

Problem

I followed the documentation of the link https://ionicframework.com/docs/native/contacts but when running on the device I get the error 'NullInjectorError: No provider for Contacts!'

Chrome Inspect Log

ERROR Error: StaticInjectorError(AppModule)[Contacts]: StaticInjectorError(Platform: core)[Contacts]: NullInjectorError: No provider for Contacts! at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get (core.js:8895) at resolveToken (core.js:9140) at tryResolveToken (core.js:9084) at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:8981) at resolveToken (core.js:9140) at tryResolveToken (core.js:9084) at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:8981) at resolveNgModuleDep (core.js:21217) at NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (core.js:21906) at injectInjectorOnly (core.js:1773)

Ionic Info

`Ionic:

ionic (Ionic CLI) : 4.12.0 (C:\Users\Leandro\AppData\Roaming\npm\node_modules\ionic)
Ionic Framework : @ionic/angular 4.1.1
@angular-devkit/build-angular : 0.13.5
@angular-devkit/schematics : 7.2.4
@angular/cli : 7.3.5
@ionic/angular-toolkit : 1.4.0

Cordova:

cordova (Cordova CLI) : 8.1.2 ([email protected])
Cordova Platforms : android 7.1.4
Cordova Plugins : not available

System:

Android SDK Tools : 26.1.1 (C:\Users\Leandro\AppData\Local\Android\Sdk)
NodeJS : v8.12.0 (C:\Program Files\nodejs\node.exe)
npm : 6.7.0
OS : Windows 7`

ionic contacts error: Cannot read property 'split' of undefined

let options = new ContactFindOptions();
options.filter='';
options.hasPhoneNumber=true;
options.multiple=true;
let contact:Contact[];
this.contacts.find(["displayName","phoneNumbers"],options).then((cont)=>{
contact=cont
})

Ionic:

ionic (Ionic CLI) : 4.1.2 (/usr/local/lib/node_modules/ionic)
Ionic Framework : ionic-angular 3.9.2
@ionic/app-scripts : 3.2.1

Cordova:

cordova (Cordova CLI) : 8.1.2 ([email protected])
Cordova Platforms : ios 4.5.5
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 2.3.2, (and 14 other plugins)

System:

ios-deploy : 2.0.0
NodeJS : v8.12.0 (/usr/local/bin/node)
npm : 6.4.1
OS : macOS
Xcode : Xcode 9.4.1 Build version 9F2000

Error:
vendor.js:1774 ERROR TypeError: Cannot read property 'split' of undefined
at get (vendor.js:71544)
at getPlugin (vendor.js:71576)
at checkAvailability (vendor.js:112501)
at vendor.js:72133
at Contacts.find (vendor.js:72140)
at OrderPage.webpackJsonp.390.OrderPage.ionViewDidLoad (main.js:1729)
at ViewController._lifecycle (vendor.js:22559)
at ViewController._didLoad (vendor.js:22442)
at Tab.NavControllerBase._didLoad (vendor.js:55759)
at t.invoke (polyfills.js:3)

Localized Phone Label (iOS)

Bug Report

Problem

What is expected to happen?

Imported contact with custom label should display 'label'

What does actually happen?

Imported contact with custom label displayed as '$!!$'

Information

Look at the label 'school'
Testing.vcf.zip

Stackoverflow Thread on similar issue

Command or Code

Environment, Platform, Device

iOS 13

Version information

Outsystems Contacts Cordova

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Spaces in Contact Phone Number are breaking search filter

Finding a contact by phoneNumbers will not return the contact unless filter string is identical to contact phone number:

Example: filter: '049999111' will return contact with phone number '0499991111'
however
Example: filter: '049999111' will not return contact with phone number '04 9999 1111'
Example: filter: '04 9999 111' will not return contact with phone number '0499991111'

Example: filter: '9111' will return contact with phone number '0499991111'
however
Example: filter: '9111' will not return contact with phone number '04 9999 1111'

Since the phone number is unknown what format it will be in, the spacing should be disregarded

Cordova 7.1.0
Cordova iOS 4.5.5
iOS 12.1 iPhone X

iOS 13 note field of contact is null

In iOS 13 I am not able to retrieve the note field.
I am able to see the note field, but not able to read it.

Does anyboday has a fix for this problem that seems only to occur for iOS 13?

Contacts plugin issue: Cannot set property 'name' of undefined

Hi,

When I try to assign this :
new ContactName(null, 'Smith', 'John');

into contact.name :
let contact: Contact = this.contacts.create();

          let usuario = new ContactName(null, 'Smith', 'John');
          console.log(typeof usuario)

          contact.name = new ContactName(null, 'Smith', 'John'); <-- failure occurs here
          contact.phoneNumbers = [new ContactField("mobile","6471234567")];
          contact.save().then(
          () => console.log("Contact saved!", contact),
          (error: any) => console.error("Error saving contact.", error)
          );
        }

I get an error:
ERROR TypeError: Cannot set property 'name' of undefined
at Contact.set [as name] (decorators.js:195)
at HomePage.add (home.ts:85)
at Object.eval [as handleEvent] (HomePage.html:191)
at handleEvent (core.js:13589)
at callWithDebugContext (core.js:15098)
at Object.debugHandleEvent [as handleEvent] (core.js:14685)
at dispatchEvent (core.js:10004)
at core.js:10629
at HTMLButtonElement. (platform-browser.js:2628)
at t.invokeTask (polyfills.js:3)

I im indeed importing :
import { Contacts, Contact, ContactField, ContactName } from '@ionic-native/contacts';
Into the page that I want to use it, and I'm importing the contacts into the constructor.

Also I'm adding into providers the
import { Contacts} from '@ionic-native/contacts';

and I have installed :
$ ionic cordova plugin add cordova-plugin-contacts
$ npm install --save @ionic-native/contacts

Best approach for searching on phone number

Feature Request

Motivation Behind Feature

The rationale for a best effort approach is e.g. reading up SMSs as "An SMS from Jim Smith: bla bla bla".

Feature Description

A method for searching for phone numbers that given any compressed number (no white space) but with or without country code provide a safe method for getting search hits.

Alternatives or Workarounds

Currently I do this, but it's not very safe:
loosify(_number.substring(3))
where loosify inserts "%" like "%1%2%3%4%". This might only work for Android, but my app is currently only for Android anyway.

Ionic 3 - Can't get android contact photo

There is some days that i search a solution to my problem.

I use the Ionic Contacts plugin ( https://ionicframework.com/docs/native/contacts/ ) and i need to get the photos of my contact list. In iOS it work but in android it won't.

I tried to sanitize,normalizeURL, and all that i found on the internet but it won't work.

Here's my code ;

home.ts

userPhoto: any;
  getContacts() {
    this.contacts.find(['displayName', 'name', 'phoneNumbers', 'emails', 'photos'], {filter: "", multiple: true})
        .then(data => {
          console.table(data[0]);
          this.userName = data[0].displayName;
          this.userPhoto = this.sanitizer.bypassSecurityTrustUrl(data[0].photos[0].value);
        });
  }

home.html

  <button ion-button (click)="getContacts()">Get contacts</button>

  <p>Nom : {{ userName }}</p>

  <hr />
  <img [src]="userPhoto" style="width: 100px;">

The error that i got in Chrome inspector:

Not allowed to load local resource: content://com.android.contacts/contacts/1/photo

Does you have any solution ?

Thanks you,

Dylan

No way to display single contact that I just added with this plugin?

Hello
I thought when I add new contact,
it should make open native contact app from phone, than show it to user notifying that "hey! I added succesfully!"

but no way. I think there's no way of doing it...
pickContract is the one that just Open contact app not specifying certain one.

How can I open contact app with a single one

cordova contacts issue

iam using ionic cordova contacts plugin ,it was working fine in android device ,but in ios device app is crashed

App crash in android 10

Bug Report

Problem

i have a app. from that app we can add ,remove and update contact in phone system when i try to create contact it is working but when i try to update contact it is keep crashing app . i aslo add read and write permission in save and remove but solution is still not work

What is expected to happen?

What does actually happen?

Information

Command or Code

Environment, Platform, Device

Version information

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Save to sim card

How can we create the contact to the sim card instead of the phone?

Support multiple find contact inside a Loop

I know this plugin is obsolete but I would like to know if anyone has ever tried to search for elements with contact.find() in a for loop on a phone number array whose names we would like to return. I have tried but the results obtained are not complete

Possible deadlock in iOS queue management code

Issue Type

  • Bug Report
  • Feature Request
  • Support Question

Description

While performing regression testing with the iOS 14 beta, I discovered that my app would crash when attempting to remove a contact. After doing some digging, it appears to be caused by potentially unnecessary calls dispatch_sync.

Information

While troubleshooting, I came upon this StackOverflow answer, which indicates that calling dispatch_sync targeting the current queue is a no-no. Through debugging my app, I discovered that this is indeed the scenario under which my app was crashing. It does not appear to crash on devices with iOS 13.

I believe I confirmed the source of the problem by changing the code in CDVContacts.m (createAddressBook) from

            dispatch_sync(dispatch_get_main_queue(), ^{
                if (error) {
                    workerBlock(NULL, [[CDVAddressBookAccessError alloc] initWithCode:UNKNOWN_ERROR]);
                } else if (!granted) {
                    workerBlock(NULL, [[CDVAddressBookAccessError alloc] initWithCode:PERMISSION_DENIED_ERROR]);
                } else {
                    // access granted
                    workerBlock(addressBook, [[CDVAddressBookAccessError alloc] initWithCode:UNKNOWN_ERROR]);
                }
            });

to

        dispatch_block_t onMain = ^{
            if (error) {
                workerBlock(NULL, [[CDVAddressBookAccessError alloc] initWithCode:UNKNOWN_ERROR]);
            } else if (!granted) {
                workerBlock(NULL, [[CDVAddressBookAccessError alloc] initWithCode:PERMISSION_DENIED_ERROR]);
            } else {
                // access granted
                workerBlock(addressBook, [[CDVAddressBookAccessError alloc] initWithCode:UNKNOWN_ERROR]);
            }
        };
        
        if ([NSThread isMainThread]) {
            onMain();
        } else {
            // callback can occur in background, address book must be accessed on thread it was created on
            dispatch_sync(dispatch_get_main_queue(), onMain);
        }

After I made this change locally and re-ran the app, the contact was successfully removed.

Command or Code

Contact.remove from @ionic-native/contacts

Environment, Platform, Device

crashed on iPad Pro: iPadOS 14 beta 2
did not crash on iPhoone XS iOS 13.6

Version information

Cordova: 9
cordova-ios: 5.1.1
cordova-plugin-contacts: 3.0.1
Ionic: 3
@ionic-native/contacts: 4.1.0

Checklist

  • I searched for already existing GitHub issues about this
  • I updated all Cordova tooling to their most recent version (this is an enterprise app for my employer -- our app stack is outdated)
  • I included all the necessary information above

undefined is not an object while calling

Hi, I have an error when trying to call contacts.create.

This is the error in the console.
"Ionic Native: tried calling Contacts.create, but the Contacts plugin is not installed"

And the image is the error in the phone.

contactsphoneerror

code:
contactocodigo

Ionic:

ionic (Ionic CLI) : 4.1.1 (C:\Users\Claudio\AppData\Roaming\npm\node_modules\ionic)
Ionic Framework : ionic-angular 3.9.2
@ionic/app-scripts : 3.2.0

Cordova:

cordova (Cordova CLI) : 8.0.0
Cordova Platforms : android 6.4.0, ios 4.5.5
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.2, (and 6 other plugins)

System:

NodeJS : v8.11.3 (C:\Program Files\nodejs\node.exe)
npm : 6.1.0
OS : Windows 10

and a fraction of the angular.json

"dependencies": {
"@agm/core": "^1.0.0-beta.3",
"@angular/animations": "5.2.11",
"@angular/common": "5.2.11",
"@angular/compiler": "5.2.11",
"@angular/compiler-cli": "5.2.11",
"@angular/core": "5.2.11",
"@angular/forms": "5.2.11",
"@angular/http": "5.2.11",
"@angular/platform-browser": "5.2.11",
"@angular/platform-browser-dynamic": "5.2.11",
"@ionic-native/barcode-scanner": "^4.12.0",
"@ionic-native/contacts": "^4.12.0",
"@ionic-native/core": "~4.12.0",
"@ionic-native/in-app-browser": "^4.12.0",
"@ionic-native/splash-screen": "~4.12.0",
"@ionic-native/status-bar": "~4.12.0",
"@ionic/storage": "2.1.3",
"angular2-google-maps": "^0.17.0",
"cordova-android": "^7.1.1",
"cordova-ios": "4.5.5",
"cordova-plugin-contacts": "^3.0.1",
"cordova-plugin-device": "^2.0.2",
"cordova-plugin-inappbrowser": "^3.0.0",
"cordova-plugin-ionic-keyboard": "^2.1.2",
"cordova-plugin-splashscreen": "^5.0.2",
"cordova-plugin-whitelist": "^1.3.3",
"ionic-angular": "3.9.2",
"ionicons": "3.0.0",
"phonegap-plugin-barcodescanner": "^8.0.0",
"rxjs": "5.5.11",
"sw-toolbox": "3.6.0",
"zone.js": "0.8.26"
},
"devDependencies": {
"@ionic/app-scripts": "3.2.0",
"typescript": "~2.6.2"
},
"description": "An Ionic project",
"cordova": {
"plugins": {
"phonegap-plugin-barcodescanner": {},
"cordova-plugin-inappbrowser": {},
"cordova-plugin-contacts": {},
"cordova-plugin-whitelist": {},
"cordova-plugin-device": {},
"cordova-plugin-splashscreen": {},
"cordova-plugin-ionic-keyboard": {}

New (Capacitor) contacts plugin to solve deprecated status

As you all know, this plugin was deprecated and no further development or bugfixing will be done. This is a major issue for everyone who uses this plugin which is a lot of people.

Now their might be a solution, but it all depends on you guys.
Capacitor is creating a list of plugins they will write and all they needs is a thumbs up from you guys to prioritize this plugin!
ionic-team/capacitor#799

What is Capacitor? Its a way to include native code into your hybrid app (a bit like cordova does but better).

Help us with your thumbs up: ionic-team/capacitor#799

In Ios not working

In android cordova-plugin-contacts works fine.
But In Ios this plugin does not work.
Following is my code.

  cordova.plugins.diagnostic.getContactsAuthorizationStatus(function(status){
    if(status === cordova.plugins.diagnostic.permissionStatus.GRANTED){
    var rpnc=JSON.parse(window.localStorage['pb']);
    var pp=[];
    function onSuccess(contacts) {
      var ppl=contacts.length;    
      for(var i=0 ;i<ppl;i++){
        for(var j=0;j<contacts[i].phoneNumbers.length;j++){
          if(rpnc.indexOf('+82'+contacts[i].phoneNumbers[j].value.replace(/[^0-9]/g,'').substring(1))==-1){
            pp.push('+82'+contacts[i].phoneNumbers[j].value.replace(/[^0-9]/g,'').substring(1));  
          }      
        }
      }
      if(pp.length>0){
        p_change1(pp);  
        var rcp=rpnc.concat(pp);
        window.localStorage['pb']=JSON.stringify(rcp);          
      }else{
        p_change2();
      }    
    };
    function onError(contactError) {
        alert('onError!');
    };
    var options      = new ContactFindOptions();
    options.filter   = "";
    options.multiple = true;
    options.desiredFields = [navigator.contacts.fieldType.id,navigator.contacts.fieldType.displayName,navigator.contacts.fieldType.phoneNumbers];
    options.hasPhoneNumber = true;
    var fields       = [navigator.contacts.fieldType.displayName, navigator.contacts.fieldType.name];
    navigator.contacts.find(fields, onSuccess, onError, options);
    }else{
      alert('permission X');    
    }
  }, function(error){
    console.error("The following error occurred: "+error);
  });

Plugin skip birthday without year on android

Bug Report

Problem

Contact with birthday, which is without year imports with empty birthday

What is expected to happen?

Expects to have contact with birthday with empty year

What does actually happen?

We have contact with empty birthday

Information

1b590002111100020000888800000000

This problem is because date without year in android passed as "--MM-DD"(https://stackoverflow.com/questions/25161485/is-the-mm-dd-format-for-month-day-part-of-iso-8601), which cannot parse by Date.valueOf method.

Command or Code

Environment, Platform, Device

Reproduced on Android 26 Pixel Emulator

Checklist

  • [ x] I searched for existing GitHub issues
  • [x ] I updated all Cordova tooling to most recent version
  • [ x] I included all the necessary information above

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.