npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cordova-plugin-contacts-x

v2.1.2

Published

Cordova Plugins for managing contacts

Downloads

1,062

Readme

ContactsX Cordova Plugin

Maintenance npm version

This Cordova Plugin is for managing Contacts. Why use this Plugin and not the "Official" one. Well, first: it's deprectated and no more work will be done there. Second (and more important): it uses a deprecated Library in iOS.

This Plugin is in active development!

Donate

This and other Open-Source Cordova Plugins are developed in my free time. To help ensure this plugin is kept updated, new features are added and bugfixes are implemented quickly, please donate a couple of dollars (or a little more if you can stretch) as this will help me to afford to dedicate time to its maintenance. Please consider donating if you're using this plugin in an app that makes you money, if you're being paid to make the app, if you're asking for new features or priority bug fixes.

Table of Content

Install

Requirements

  • cordova >= 9.0.0
  • cordova-android >= 9.0.0
  • ios >= 9
  • android >= 22

Android

For normalization the plugin implements Google - libphonenumber

iOS

This Plugin is developed in Swift and automaticaly adds the Plugin to Support Swift.

I developed it, testing with [email protected].

For normalization on iOS the plugin implements marmelroy - PhoneNumberKit

Environment Variables

iOS

The iOS platform defines:

  • NSContactsUsageDescription: This app requires access to the contacts to manage them.

You can easily change it, by configure your config.xml by:

<edit-config file="*-Info.plist" mode="merge" target="NSContactsUsageDescription">
    <string>your text</string>
</edit-config>

Usage

The plugin is available via a global variable named window.ContactsX. A TypeScript definition is included out of the Box. You can import it like this:

import ContactsX from 'cordova-plugin-contacts-x';

Failure Callbacks

If an Error appeared this Plugin returns an Object in the failureCallback, that always has the following Structure:

{
  "code": 0,
  "message": "Some additional Info"
}

The code is one of the Error Codes and always present, while the message can be empty. This is mostly something like an Exception Message.

Error Codes

The following Error Codes can be fired by this Plugin:

  • UnsupportedAction
  • WrongJsonObject
  • PermissionDenied
  • UnknownError

They can be accessed over window.ContactsX.ErrorCodes and are present in the TypeScript definition too of course.

Normalization E.164

If baseCountryCode is passed as an option to the find method, the plugin attempts to resolve the normalized phone numbers in E.164 format. Setting a wrong (ISO 3166-1 alpha-2) value would cause the libary to not be able to (correctly) resolve the normalized number. Typically the value should correspond to the device (SIM) country.

Output example

Assuming that the device is from the "Netherlands", the correct baseCountryCode would be "NL".

| baseCountryCode:| "NL" | "US" | ""| |-------------------|--------------|--------------|-----| | +49 151 12345 | +4915112345 | +4915112345" | "" | | (06) 123 4567 | +3161234567 | "" | "" | | +1 (424) 555-1234 | +14245551234 | +14245551234 | "" | | +31 (0) 6 987 654 | +316987654 | +316987654 | "" |

For context the "nationalNumber" of the Netherlands is "+31"

Api

The list of available methods for this plugin is described below.

hasPermission

Parameters:

  • Success Callback
  • Error Callback
window.ContactsX.hasPermission(function(success) {
  console.log(success);
}, function (error) {
  console.error(error);
});

SuccessType:

This Method returns an Object with the following field:

  • read (boolean) has read permission
  • write (boolean) has write permission

Quirks

Apple only has one Permission, so in iOS read and write are always the same value.

requestPermission

Request Contact Permission

Parameters:

  • Success Callback
  • Error Callback
window.ContactsX.requestPermission(function(success) {
  console.log(success);
}, function (error) {
  console.error(error);
});

SuccessType:

Same SuccessType as hasPermission()

requestWritePermission

Request Contact Write Permission (android only)

Parameters:

  • Success Callback
  • Error Callback
window.ContactsX.requestWritePermission(function(success) {
  console.log(success);
}, function (error) {
  console.error(error);
});

SuccessType:

Same SuccessType as hasPermission()

find

Find Contacts by given options. If you don't set a field in fields to true, it is not included or empty in the result. When baseCountryCode is defined (using a valid ISO 3166-1 alpha 2 code), the plugin attempts to resolve the normalized E.164 phone numbers in the phoneNumbers Array.

Parameters:

  • Success Callback
  • Error Callback
  • Options:
    • fields:
      • displayName (boolean) - Android only, default: true
      • firstName (boolean) - default: true
      • middleName (boolean) - default: true
      • familyName (boolean) - default: true
      • organizationName (boolean) - default: true
      • phoneNumbers (boolean)
      • emails (boolean)
    • baseCountryCode (string) - default: null
window.ContactsX.find(function(success) {
  console.log(success);
}, function (error) {
  console.error(error);
}, {
  fields: {
    phoneNumbers: true
  },
  baseCountryCode : 'GB'
});

SuccessType:

This Method returns an Array of ContactX.

pick

Launches the Contact Picker to select a single contact. Currently, all available fields are returned.

Parameters:

  • Success Callback
  • Error Callback
window.ContactsX.pick(function(success) {
  console.log(success);
}, function (error) {
  console.error(error);
});

SuccessType:

This Method returns a single ContactX object.

save

Save or update a contact. If you provide the id the contact will be updated. (remember to add rawId on android also).

Parameters:

  • contact (ContactX)
  • Success Callback
  • Error Callback
window.ContactsX.save(
  {
    firstName: "Hans",
    familyName: "Test",
    organizationName : "Einfach",
    phoneNumebers: [{
      type: "mobile",
      value: "110"
    }]
  },
  function(success) {
    console.log(success);
  },
  function (error) {
  console.error(error);
});

SuccessType:

This Method returns the final ContactX object.

delete

Delete a contact by id

Parameters:

  • id (string)
  • Success Callback
  • Error Callback
window.ContactsX.delete("some_id",
  function(success) {
    console.log(success);
  },
  function (error) {
  console.error(error);
});

Objects

ContactX

  • id (string) - a unique identifier
  • displayName (string) - Android only
  • firstName (string)
  • middleName (string)
  • familyName (string)
  • organizationName (string)
  • phoneNumbers (ContactXPhoneNumber[])
  • emails (ContactXEmail[])

ContactXPhoneNumber

  • id (string)
  • normalized (string) if baseCountryCode is set/valid
  • type (string)
  • value (string)

ContactXEmail

  • id (string)
  • type (string)
  • value (string)

Changelog

The full Changelog is available here