Coder Social home page Coder Social logo

nativescript-contacts's People

Contributors

abhayastudios avatar ashishwadekar avatar bthurlow avatar cfjedimaster avatar dlcole avatar firescript avatar fpaaske avatar jorwoody avatar jzgoda avatar nathanwalker avatar neddinn avatar nitayrabi avatar peterstaev avatar sitefinitysteve avatar sserdyuk avatar steinerj avatar tqhsonoma 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nativescript-contacts's Issues

Fatal crash in iOS

Referencing this module, as described in the README, is crashing in iOS 13.4. This appears to be related to the availability of CNContactPickerViewController at runtime.

$ tns info
✔ Getting NativeScript components versions information...
✔ Component nativescript has 6.5.0 version and is up to date.
✔ Component tns-core-modules has 6.5.1 version and is up to date.
✔ Component tns-android has 6.5.0 version and is up to date.
✔ Component tns-ios has 6.5.0 version and is up to date.

Section that caught my attention:

Error: Class "CNContactPickerViewController" referenced by type encoding not found at runtime.

Full stack trace:

CONSOLE INFO file: node_modules/nativescript-dev-webpack/hot.js:3:0: HMR: Checking for updates to the bundle with hmr hash 6561b1f228d2f1473cf5.
CONSOLE INFO file: node_modules/nativescript-dev-webpack/hot.js:3:0: HMR: The following modules were updated:
CONSOLE INFO file: node_modules/nativescript-dev-webpack/hot.js:3:0: HMR:          ↻ ../node_modules/nativescript-contacts/index.js
CONSOLE INFO file: node_modules/nativescript-dev-webpack/hot.js:3:0: HMR:          ↻ ./app/social/local-contacts.service.ts
CONSOLE INFO file: node_modules/nativescript-dev-webpack/hot.js:3:0: HMR:          ↻ ./app/social/social.effects.ts
CONSOLE INFO file: node_modules/nativescript-dev-webpack/hot.js:3:0: HMR:          ↻ ./app/social/social.module.ts
CONSOLE INFO file: node_modules/nativescript-dev-webpack/hot.js:3:0: HMR:          ↻ ./app/create-account/create-account.module.ts
CONSOLE INFO file: node_modules/nativescript-dev-webpack/hot.js:3:0: HMR:          ↻ ./app/app-routing.module.ts
CONSOLE INFO file: node_modules/nativescript-dev-webpack/hot.js:3:0: HMR:          ↻ ./app/app.module.ts
CONSOLE INFO file: node_modules/nativescript-dev-webpack/hot.js:3:0: HMR: Successfully applied update with hmr hash 6561b1f228d2f1473cf5. App is up to date.
CONSOLE LOG file: node_modules/@angular/core/fesm5/core.js:25638:0: Angular is running in the development mode. Call enableProdMode() to enable the production mode.
***** Fatal JavaScript exception - application has been terminated. *****
Native stack trace:
1   0x10643360e NativeScript::reportFatalErrorBeforeShutdown(JSC::ExecState*, JSC::Exception*, bool)
2   0x106482f76 -[TNSRuntimeInspector reportFatalError:]
3   0x105d1725b TNSInspectorUncaughtExceptionHandler
4   0x7fff23e3e12d __handleUncaughtException
5   0x7fff50b3bc05 _objc_terminate()
6   0x7fff4f986c87 std::__terminate(void (*)())
7   0x7fff4f98940b __cxa_get_exception_ptr
8   0x7fff4f9893d2 __cxxabiv1::exception_cleanup_func(_Unwind_Reason_Code, _Unwind_Exception*)
9   0x7fff50b3bad6 _objc_exception_destructor(void*)
10  0x10648a0f0 NativeScript::TypeFactory::parseType(NativeScript::GlobalObject*, Metadata::TypeEncoding const*&, bool)
11  0x10648abe9 NativeScript::TypeFactory::parseTypes(NativeScript::GlobalObject*, Metadata::TypeEncoding const*&, int, bool)
12  0x10646f942 NativeScript::ObjCMethodWrapper::finishCreation(JSC::VM&, NativeScript::GlobalObject*, WTF::HashSet<Metadata::MemberMeta const*, WTF::PtrHash<Metadata::MemberMeta const*>, WTF::HashTraits<Metadata::MemberMeta const*> >)
13  0x10645911a NativeScript::ObjCMethodWrapper::create(JSC::VM&, NativeScript::GlobalObject*, JSC::Structure*, WTF::HashSet<Metadata::MemberMeta const*, WTF::PtrHash<Metadata::MemberMeta const*>, WTF::HashTraits<Metadata::MemberMeta const*> >)
14  0x106471c68 NativeScript::overrideObjcMethodCalls(JSC::ExecState*, JSC::JSObject*, JSC::PropertyName, JSC::JSCell*, Metadata::BaseClassMeta const*, Metadata::MemberType, objc_class*, WTF::Vector<Metadata::ProtocolMeta const*, 0ul, WTF::CrashOnOverflow, 16ul> const&)
15  0x10645efc1 NativeScript::ObjCClassBuilder::addInstanceMethod(JSC::ExecState*, JSC::Identifier const&, JSC::JSCell*)
16  0x106464fd0 NativeScript::ObjCClassBuilder::addInstanceMembers(JSC::ExecState*, JSC::JSObject*, JSC::JSValue)
17  0x106469274 NativeScript::ObjCExtendFunction(JSC::ExecState*)
18  0x420119e0116b
19  0x106e6af7f llint_entry
20  0x420119e1f80e
21  0x42011a118b61
22  0x106e6af7f llint_entry
23  0x420119e1f80e
24  0x42011a118b61
25  0x106e6af7f llint_entry
26  0x420119e1f80e
27  0x42011a118b61
28  0x106e6af7f llint_entry
29  0x420119e1f80e
30  0x42011a118b61
31  0x106e6af7f llint_entry
JavaScript stack trace:
extend(file: node_modules/nativescript-contacts/index.ios.js:6:0)
at ../node_modules/nativescript-contacts/index.js(file: node_modules/nativescript-contacts/index.ios.js:6:0)
at __webpack_require__(file: src/webpack/bootstrap:750:0)
at fn(file: src/webpack/bootstrap:120:0)
at ./app/social/local-contacts.service.ts(file: src/app/social/local-contacts.service.ts:1:0)
at __webpack_require__(file: src/webpack/bootstrap:750:0)
at fn(file: src/webpack/bootstrap:120:0)
at ./app/social/social.effects.ts(file: src/app/social/social.effects.ts:1:0)
at __webpack_require__(file: src/webpack/bootstrap:750:0)
at fn(file: src/webpack/bootstrap:120:0)
at ./app/social/social.module.ts(file: src/app/social/social.module.ts:1:0)
at __webpack_require__(file: src/webpack/bootstrap:750:0)
at fn(file: src/webpack/bootstrap:120:0)
at ./app/create-account/create-account.module.ts(file: src/app/create-account/create-account.module.ts:1:0)
at __webpack_require__(file: src/webpack/bootstrap:750:0)
at fn(file: src/webpack/bootstrap:120:0)
at fn([native code])
at onInvoke(file: node_modules/@angular/core/fesm5/core.js:26256:0)
at file: node_modules/@nativescript/angular/zone-js/dist/zone-nativescript.js:138:0
at file:///app/vendor<…>
JavaScript error:
file: node_modules/nativescript-contacts/index.ios.js:6:0: JS ERROR Error: Class "CNContactPickerViewController" referenced by type encoding not found at runtime.
NativeScript caught signal 6.
Native Stack:
1   0x106484251 sig_handler(int)
2   0x7fff51b965fd _sigtramp
3   0x7fff51a8ac19 itoa64
4   0x7fff51a8685c abort
5   0x7fff4f987858 abort_message
6   0x7fff4f986cad std::__terminate(void (*)())
7   0x7fff4f98940b __cxa_get_exception_ptr
8   0x7fff4f9893d2 __cxxabiv1::exception_cleanup_func(_Unwind_Reason_Code, _Unwind_Exception*)
9   0x7fff50b3bad6 _objc_exception_destructor(void*)
10  0x10648a0f0 NativeScript::TypeFactory::parseType(NativeScript::GlobalObject*, Metadata::TypeEncoding const*&, bool)
11  0x10648abe9 NativeScript::TypeFactory::parseTypes(NativeScript::GlobalObject*, Metadata::TypeEncoding const*&, int, bool)
12  0x10646f942 NativeScript::ObjCMethodWrapper::finishCreation(JSC::VM&, NativeScript::GlobalObject*, WTF::HashSet<Metadata::MemberMeta const*, WTF::PtrHash<Metadata::MemberMeta const*>, WTF::HashTraits<Metadata::MemberMeta const*> >)
13  0x10645911a NativeScript::ObjCMethodWrapper::create(JSC::VM&, NativeScript::GlobalObject*, JSC::Structure*, WTF::HashSet<Metadata::MemberMeta const*, WTF::PtrHash<Metadata::MemberMeta const*>, WTF::HashTraits<Metadata::MemberMeta const*> >)
14  0x106471c68 NativeScript::overrideObjcMethodCalls(JSC::ExecState*, JSC::JSObject*, JSC::PropertyName, JSC::JSCell*, Metadata::BaseClassMeta const*, Metadata::MemberType, objc_class*, WTF::Vector<Metadata::ProtocolMeta const*, 0ul, WTF::CrashOnOverflow, 16ul> const&)
15  0x10645efc1 NativeScript::ObjCClassBuilder::addInstanceMethod(JSC::ExecState*, JSC::Identifier const&, JSC::JSCell*)
16  0x106464fd0 NativeScript::ObjCClassBuilder::addInstanceMembers(JSC::ExecState*, JSC::JSObject*, JSC::JSValue)
17  0x106469274 NativeScript::ObjCExtendFunction(JSC::ExecState*)
18  0x420119e0116b
19  0x106e6af7f llint_entry
20  0x420119e1f80e
21  0x42011a118b61
22  0x106e6af7f llint_entry
23  0x420119e1f80e
24  0x42011a118b61
25  0x106e6af7f llint_entry
26  0x420119e1f80e
27  0x42011a118b61
28  0x106e6af7f llint_entry
29  0x420119e1f80e
30  0x42011a118b61
31  0x106e6af7f llint_entry
JS Stack:
extend([native code])
at ../node_modules/nativescript-contacts/index.js(file: node_modules/nativescript-contacts/index.ios.js:6:0)
at __webpack_require__(file: src/webpack/bootstrap:750:0)
at fn(file: src/webpack/bootstrap:120:0)
at ./app/social/local-contacts.service.ts(file: src/app/social/local-contacts.service.ts:1:0)
at __webpack_require__(file: src/webpack/bootstrap:750:0)
at fn(file: src/webpack/bootstrap:120:0)
at ./app/social/social.effects.ts(file: src/app/social/social.effects.ts:1:0)
at __webpack_require__(file: src/webpack/bootstrap:750:0)
at fn(file: src/webpack/bootstrap:120:0)
at ./app/social/social.module.ts(file: src/app/social/social.module.ts:1:0)
at __webpack_require__(file: src/webpack/bootstrap:750:0)
at fn(file: src/webpack/bootstrap:120:0)
at ./app/create-account/create-account.module.ts(file: src/app/create-account/create-account.module.ts:1:0)
at __webpack_require__(file: src/webpack/bootstrap:750:0)
at fn(file: src/webpack/bootstrap:120:0)
at fn([native code])
at onInvoke(file: node_modules/@angular/core/fesm5/core.js:26256:0)
at file: node_modules/@nativescript/angular/zone-js/dist/zone-nativescript.js:138:0
at file: node_modules/@nativescript/angular/zone-js/dist/zone-nativescript.js:883:0
at onInvokeTask(file:///app/vendo<…>

A couple of minor feature "requests"

Hi,
I'm new to NativeScript, but have benefitted from this plugin - thanks!
However, it would be nice if:

  1. One could ensure that the contacts didn't obscure a tabbed view selector
  2. One could specify the animation used in launching the contacts (i.e. maybe not having it just slide up from the bottom).
    I presume that these are not already available...
    ...but can I easily edit the source to make this possible?

getContactsInGroup() not taking parameters

When i do;

var group = args.data[0]
contacts.getContactsInGroup(group)

I get the error: Supplied parameters do not match any signature of call target. In fact, all of the other functions that are supposed to take a parameter throw that error. The function getContact(), works well.

I'm using NS 3.0 with Angular/TS.

No Accounts! Error message, when no account is configured in device

Hi,

When my phone is not configured with any account and when i try to add a contact through my app, it throws the following error
JS: Error: No Accounts! JS: at Contact.save (file:///data/data/com.bcbsma.myblue2/files/app/tns_modules/nativescript-contacts/contact-model.js:227:19) [angular]

Can you please let us know what happens?

Device: All Android and IOS devices

Allow getAllContacts parameter to be optional

It would be helpful if the contactFields parameter in the getAllContacts method was optional. When not provided, all available contactFields should be returned.

(It appears this is already the behavior in the Android version of the worker and model.)

ios permissions

Hi

Could I please find out where is the code that prompts access to contacts permissions to be granted on ios?
And how to check if this is granted.
I did a bit of googling i think for ios its CNAuthorizationStatus and requestAccessForEntityType
Could you please integrate to check if access is granted for both ios and android? Wont take you long but will take me ages.

Thanks

Not able to save a contact on iOS

Hello,

First of all. Thanks for making this awesome plugin to make is very easy to manage contacts 🙌

I am having an issue while saving a new contact in Vue Nativwscript enivronment. I am able to successfully read contact as explained in the example.

Sharing the code here:

import * as ContactHelper from "nativescript-contacts";
import * as app from "application";

onContactButtonTap() {
      var contactBuilder = new ContactHelper.Contact();

      if (this.contactDetails.first_name) {
        contactBuilder.name.given = this.contactDetails.first_name;
      }

      if (this.contactDetails.last_name) {
        contactBuilder.name.family = this.contactDetails.last_name;
      }
      contactBuilder.save();
}

Added the Privacy - Contact key in info.plist:

<key>Privacy - Contacts Usage Description</key>
		<string>Kindly provide permission to save selected contact to phone.</string>

Can you help me in getting this to work? Thanks.

Cheers,
Ashish

notes bug on iOS

Hi,

I was unable to save notes on iOS. and after trying countless things I noticed that the problem is the notes field in iOS is actually (NOTE) and NOT (NOTES). it would be great if you can submit a fix for this.

Thanks

AOT Build issue: contacts Could not find module './get-all-contacts-worker.js

the plugin is working fine in the normal release build mode but when we build in the AOT release mode the app crashes can you please look at the below error messages

JS ERROR Error: Could not find module './get-all-contacts-worker.js'. Computed path '/var/mobile/Containers/Data/Application/2896D048-EF2B-4A21-ABDF-E08EF46154E9/Library/Application Support/LiveSync/app/get-all-contacts-worker.js'.
JS ERROR TypeError: console.dump is not a function. (In 'console.dump(e)', 'console.dump' is undefined)

kindly help us

Permission error on android even though permission is set on manifest file.

I'm getting the following error on android:
JS: Error: Error: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.ContactsProvider2 from ProcessRecord{258e81c 3198:com.ink.application/u0a90} (pid=3198, uid=10090) requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS

Though I've set the permission on AndroidManifest.xml as:

<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />

I'm using this within a angular app. Does it matter?
The code that accesses the contact is here:

    let contacts = require( 'nativescript-contacts' );
    contacts.getAllContacts().then((contacts) => {
      contacts.data.forEach((contact) => {
        let name = contact.name.given + ' ' + contact.name.family;
        let phones = contact.phoneNumbers.map((phoneNumber) => {
          return phoneNumber.value;
        });
        this.contactsList.push({ name, phones });
      });
    },
    (err) => {
      console.log('Error: ' + err);
    });

TypeError: null is not an object (evaluating 'foundContacts.count')

Here is my code:

addressbook.getContact().then((args) =>{
if (args.response === "selected") {
let contact = args.data;
console.log(JSON.stringify(contact));
//contact.name.given = contact.First_Name;
//contact.name.family = contact.Last_Name;
contact.save();
}
});

I got anerror when i try to update:

CONSOLE LOG file:///src/app/services/addressbook.service.ts:102:34: {"id":"1A5D9C7D-AE0C-4DBA-B35F-2E9C610F6995:ABPerson","name":{"given":"4Corners Images","middle":"","family":"","prefix":"","suffix":"","displayname":"","phonetic":{"given":"","middle":"","family":""}},"organization":{"name":"","jobTitle":"","department":""},"nickname":"","notes":"","urls":[],"phoneNumbers":[{"id":"B6E13834-C108-4F9F-B072-D2EFC8F870EB","label":null,"value":"+123"}],"emailAddresses":[{"id":"9F114A07-F0DA-483B-AA7A-0B8122D904D3","label":null,"value":"[email protected]"}]}

CONSOLE ERROR file:///node_modules/@angular/core/fesm5/core.js:4002:0: ERROR Error: Uncaught (in promise): TypeError: null is not an object (evaluating 'foundContacts.count')
save(file:///node_modules/nativescript-contacts/contact-model.js:136:0)
at file:///src/app/services/addressbook.service.ts:107:34
at onInvoke(file:///node_modules/@angular/core/fesm5/core.js:26255:0)
at run(file:///node_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:138:0)
at file:///node_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:883:0
at onInvokeTask(file:///node_modules/@angular/core/fesm5/core.js:26246:0)
at runTask(file:///node_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:188:0)
at drainMicroTaskQueue(file:///node_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:595:0)
at promiseReactionJob([native code])
at UIApplicationMain([native code])
at _start(file:///node_modules/tns-core-modules/application/application.js:295:0)
at run(file:///node_modules/tns-core-modules/application/application.js:323:0)
at bootstrapNativeScriptApp(file:///node_modules/nativescript-angular/platform-common.js:210:0)
at bootstrapApp(file:///node_modules/nativescript-angular/platform-common.js:111:0)
at bootstrapModule(file:///node_modules/nativescript-angular/platform-common.js:91:0)
at file:///app/bundle.js:1120:144
at ./main.ts(file:///app/bundle.js:1125:34)
at webpack_require(file:///src/webpack/bootstrap:750:0)
at checkDeferredModules(file:///src/webpack/bootstrap:43:0)

ImageSource error

I can not use the ImageSource object for the photo of the contact when I try to use it returns me " Error in downloadBitmap - java.net.MalformedURLException: Protocol not found: [object Object] ", I had to convert to base 64 and show it this way , there is something that has been wrong

plugin doesn't properly retrieve photos on Android

For contacts that have a photo defined on Android the plugin doesn't return the URL as expected:

{
  "id": 353,
  "name": { <correct name object> },
  "photo": {
    "android": {}
  }
}

Contacts for which a photo does actually not exist it will return just a null:

{
  "id": 1058,
  "name": { <correct name object> },
  "photo": null,
}

getAllContacts method not Webpack compatible

@firescript the method getAllContacts is using a Worker it must be also made Webpack compatible.

e.g. change this line

orker = new Worker('./get-all-contacts-worker.js'); // relative for caller script path

to

var worker;
        if (global["TNS_WEBPACK"]) {
            var myWorker = require('nativescript-worker-loader!./get-all-contacts-worker.js.js');
            worker = new myWorker();
        } else {
            worker = new Worker('./get-all-contacts-worker.js'); // relative for caller script path
        }

Update existing contact throwing an error (Android Only)

Hi, Thanks for your plugin.
I have an issue only on Android devices occurs in this line:
contact.save();
throw this error:

Error: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.net.Uri.getLastPathSegment()' on a null object reference
JS: android.content.ContentUris.parseId(ContentUris.java:85)
JS: com.tns.Runtime.callJSMethodNative(Native Method)
JS: com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1021)
JS: com.tns.Runtime.callJSMethodImpl(Runtime.java:903)
JS: com.tns.Runtime.callJSMethod(Runtime.java:890)
JS: com.tns.Runtime.callJSMethod(Runtime.java:874)
JS: com.tns.Runtime.callJSMethod(Runtime.java:866)
JS: com.tns.NativeScriptActivity.onActivityResult(NativeScriptActivity.java:69)
JS: android.app.Activity.dispatchActivityResult(Activity.java:6428)
JS: android.app.ActivityThread.deliverResults(ActivityThread.java:3695)
JS: android.app.ActivityThread.handleSendResult(ActivityThread.java:3742)
JS: android.app.ActivityThread.-wrap16(ActivityThread.java)
JS: android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393)
JS: android.os.Handler.dispatchMessage(Handler.java:102)
JS: android.os.Looper.loop(Looper.java:148)
JS: android.app.ActivityThread.main(ActivityThread.java:5417)
JS: java.lang.reflect.Method.invoke(Native Method)
JS: com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
JS: com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

when trying to update an existing contact.
I've tested on Android v6.0.0 and 7.0.0
in the attachments bellow test code generate the issue.
Thanks in advanced.
my-contacts.zip

Issue while doing a webpack

Hi,

I am having issue while doing a webpack. Following is the issue I am getting

"ERROR in ../node_modules/nativescript-contacts/index.android.js
Module not found: Error: Can't resolve './get-contacts-by-name-worker.js'"

I am using tns 3.2.1

Please update npm

Can the latest version please be updated on NPM?
The last version posted was 1.5.5, from 10 months ago.

Thanks!

No Data Returned

Hello,

I am using the plugin this way
contacts.getAllContacts(['name', 'organization', 'phoneNumbers', 'emailAddresses', 'postalAddresses']).then((contacts) => { alert(JSON.stringify(contacts)); });

It works fine when I am testing on the emulator and on my phone LG Stylus built in release mode.

However, for someone else that has a samsung galaxy s7 active, all that is displayed is {"nativeException":{}}

Does anyone have an idea what kind of problem this is? I haven't tested on other phones yet. Also, the galaxy s7 has 180+ contacts.

Slow perfornmance

I am using a physical android device (Node 9) to test. The NS version is 6.2.1.

When I load the contacts it takes over 30 seconds to load 827 contacts. Is this normal? Is there a way to speed things up?

Here is my code:

function getContacts() {
    //get the contacts
    console.log('start', new Date());
    var contactFields = ["name", "phoneNumbers"];
    contacts.getAllContacts(contactFields).then(
        function (args) {
            console.log('end', new Date());
        },
        function (err) {
            console.log("Error: " + err);
        }
    );
}

Here is my package.json:

{
  "nativescript": {
    "id": "io.company.app",
    "tns-android": {
      "version": "6.2.0"
    }
  },
  "main": "app.js",
  "description": "NativeScript Application",
  "license": "SEE LICENSE IN <your-license-filename>",
  "repository": "<fill-your-repository-here>",
  "dependencies": {
    "@nstudio/nativescript-camera-plus": "3.0.5",
    "@nstudio/nativescript-loading-indicator": "^1.0.0",
    "nativescript-contacts": "^1.6.2",
    "nativescript-fonticon": "^2.0.0",
    "nativescript-masked-text-field": "4.0.3",
    "nativescript-permissions": "^1.3.8",
    "nativescript-theme-core": "2.0.5",
    "nativescript-ui-listview": "^8.0.1",
    "tns-core-modules": "6.2.1",
    "tns-platform-declarations": "6.2.1"
  },
  "devDependencies": {
    "nativescript-dev-webpack": "1.3.0",
    "typescript": "3.4.5"
  },
  "gitHead": "f28dbc60d74dd2cef4b645afd8fdd63bbb12c73e",
  "readme": "NativeScript Application"
}

Thanks

Not Able to Pass the Retrieved Contact to My Own API Service

I am able to get the contact from the phone using nativescript-contacts but I am unable to pass it to my API which is in a custom function from contacts.getContact().then(function (args) {} method.

I defined a PUBLIC VARIABLE (Object or String or Array) to which I am trying to store the contact but this is not working. It is showing an error

ERROR Error: Uncaught (in promise): TypeError: undefined is not an object (evaluating 'PUBLIC VARIABLE')

Save new contact error: No Accounts!

Hi,
I working on a nativescript app for android and iOS. I want implement a feature to add contacts to the device. Therefore I tested this plugin. I used exactly the code from npm plugin website for Save a new contact to do this. But on emulator and also on android device it stops with this error message:

Error: No Accounts! .../app/tns_modules/nativescript-contacts/contact-model.js, line: 200, column: 12

getContactsInGroup() error if group has no contacts

If you getContactsInGroup() with a group that has no contacts, the following error is thrown:

CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:15769:28: ERROR Error: Uncaught (in promise): TypeError: null is not an object (evaluating 'foundContacts.count')
file:///app/tns_modules/nativescript-contacts/index.js:198:26

It's caused by a missing null check in the following line:

if (foundContacts.count > 0) {

I'll issue a PR for this.

FileNotFoundException

I've been trying to get all the contacts from my phone's contact list with the getAllContacts() function. I have been encountering an error I can't seem to fix:

Error: Error
java.io.FileNotFoundException: content://com.android.contacts/contacts/1/photo

I can access the native list just fine, and I can pull single contacts just fine, but I'd prefer the functionality of being able to pull the entire list.

Any suggestions?

A Frame must be used to navigate to a Page

Please help, i get an error

my scripts:

let app = require( "application" );
let Permissions = require( "nativescript-permissions" );
let contacts = require('nativescript-contacts');
var imageSource = require( "image-source" );

var newContact = new contacts.Contact();
			newContact.name.given = "John";
			newContact.name.family = "Doe";
			newContact.phoneNumbers.push({ label: contacts.KnownLabel.HOME, value: "123457890" }); // See below for known labels
			newContact.save();

Error log
System.err: Calling js method onCreate failed
System.err:
System.err: Error: A Frame must be used to navigate to a Page.
System.err: File: "file:///data/data/org.nativescript.application/files/app/tns_modules/tns-core-modules/ui/frame/frame.js, line: 605, column: 16
System.err:
System.err: StackTrace:
System.err: Frame: function:'ActivityCallbacksImplementation.onCreate', file:'file:///data/data/org.nativescript.application/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 605, column: 23
System.err: Frame: function:'NativeScriptActivity.onCreate', file:'file:///data/data/org.nativescript.application/files/app/tns_modules/tns-core-modules/ui/frame/activity.js', line: 20, column: 25
System.err:
System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2724)
System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2785)
System.err: at android.app.ActivityThread.-wrap12(ActivityThread.java)
System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1532)
System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
System.err: at android.os.Looper.loop(Looper.java:163)
System.err: at android.app.ActivityThread.main(ActivityThread.java:6342)
System.err: at java.lang.reflect.Method.invoke(Native Method)
System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:880)
System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770)
System.err: Caused by: com.tns.NativeScriptException:
System.err: Calling js method onCreate failed
System.err:
System.err: Error: A Frame must be used to navigate to a Page.
System.err: File: "file:///data/data/org.nativescript.application/files/app/tns_modules/tns-core-modules/ui/frame/frame.js, line: 605, column: 16
System.err:
System.err: StackTrace:
System.err: Frame: function:'ActivityCallbacksImplementation.onCreate', file:'file:///data/data/org.nativescript.application/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 605, column: 23
System.err: Frame: function:'NativeScriptActivity.onCreate', file:'file:///data/data/org.nativescript.application/files/app/tns_modules/tns-core-modules/ui/frame/activity.js', line: 20, column: 25
System.err:
System.err: at com.tns.Runtime.callJSMethodNative(Native Method)
System.err: at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1088)
System.err: at com.tns.Runtime.callJSMethodImpl(Runtime.java:970)
System.err: at com.tns.Runtime.callJSMethod(Runtime.java:957)
System.err: at com.tns.Runtime.callJSMethod(Runtime.java:941)
System.err: at com.tns.Runtime.callJSMethod(Runtime.java:933)
System.err: at com.tns.NativeScriptActivity.onCreate(NativeScriptActivity.java:13)
System.err: at android.app.Activity.performCreate(Activity.java:6847)
System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2677)
System.err: ... 9 more
ActivityManager: report kill process: killerPid is:3172, killedPid is:3172
ActivityManager: Process org.nativescript.application (pid 3172) has died: fore T
ActivityManager: cleanUpApplicationRecord -- 3172

package.json

{
"name": "XXX",
"version": "1.0.0",
"description": "A native application built with NativeScript-Vue",
"author": "Levi",
"license": "MIT",
"scripts": {
"build": "webpack --env.tnsAction build",
"build:android": "npm run build -- --env.android",
"build:ios": "npm run build -- --env.ios",
"debug": "webpack --watch --env.tnsAction debug",
"debug:android": "npm run debug -- --env.android",
"debug:ios": "npm run debug -- --env.ios",
"watch": "webpack --watch --env.tnsAction run",
"watch:android": "npm run watch -- --env.android",
"watch:ios": "npm run watch -- --env.ios",
"clean": "rimraf dist"
},
"dependencies": {
"child_process": "^1.0.2",
"nativescript-background-http": "^3.2.6",
"nativescript-contacts": "^1.5.4",
"nativescript-contacts-lite": "^0.2.5",
"nativescript-exit": "^1.0.1",
"nativescript-fonticon": "^1.1.1",
"nativescript-imagepicker": "^6.0.2",
"nativescript-localstorage": "^1.1.5",
"nativescript-permissions": "^1.2.3",
"nativescript-ripple": "^2.0.0",
"nativescript-snackbar": "^3.1.0",
"nativescript-socketio": "^2.5.0",
"nativescript-theme-core": "^1.0.4",
"nativescript-vue": "^1.3.1",
"tns-core-modules": "~3.4.1",
"vue-router": "^3.0.1",
"vuex": "^3.0.1"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.4",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.6.1",
"copy-webpack-plugin": "^4.5.1",
"css-loader": "^0.28.11",
"extract-text-webpack-plugin": "^3.0.2",
"fs-extra": "^5.0.0",
"nativescript-vue-externals": "^0.2.0",
"nativescript-vue-loader": "^0.1.5",
"nativescript-vue-target": "^0.1.0",
"nativescript-vue-template-compiler": "^1.3.1",
"nativescript-worker-loader": "^0.9.0",
"node-sass": "^4.7.2",
"ns-vue-loader": "^0.1.2",
"optimize-css-assets-webpack-plugin": "^3.2.0",
"rimraf": "^2.6.2",
"sass-loader": "^6.0.7",
"vue-template-compiler": "^2.5.16",
"webpack": "^3.11.0",
"webpack-synchronizable-shell-plugin": "0.0.7",
"winston-color": "^1.0.0"
}
}

Porting to NativeScript 3.0

Hello there,
This useful plugin doesn't work on NativeScript 3.0. I am using getContact(), and it's Promise return doesn't seem to call its callbacks. Any interest in porting the plugin to {N} 3.0?

Always triggering HMR / Webpack

For some reason, whenever I make a change to my code, some of nativescript-contacts files get triggered by Webpack, which in turn makes HMR do a full restart of the app, instead of just updating the app without a full restart. Check log:

JS: HMR: The following modules were updated:
JS: HMR:          ↻ ../node_modules/nativescript-worker-loader/index.js!../node_modules/nativescript-contacts/get-all-contacts-worker.js
JS: HMR:          ↻ ../node_modules/nativescript-worker-loader/index.js!../node_modules/nativescript-contacts/get-contacts-by-name-worker.js

Photo issue to base64

Platform: ios

method call: getAllContacts()

config: const desiredFields = ["name", "phoneNumbers", "photo"];

code called: contact.photo && contact.photo.toBase64String("png")

Error: getAllContacts Catch: TypeError: contact.photo.toBase64String is not a function. (In 'contact.photo.toBase64String("png")', 'contact.photo.toBase64String' is undefined)

This happens on the first object with image:

{
"id": "412412412",
"name": {
"given": "Bill",
"middle": "",
"family": "Jobs",
"prefix": "",
"suffix": "",
"displayname": "",
"phonetic": {
"given": "",
"middle": "",
"family": ""
}
},
"organization": {
"name": "",
"jobTitle": "",
"department": ""
},
"nickname": "",
"notes": "",
"photo": {
"ios": {}
},
"urls": [],
"phoneNumbers": [
{
"id": "12412412412412",
"label": "Mobile",
"value": "XXXXXXXXXX"
}
],
"emailAddresses": [],
"postalAddresses": []
}

I also tried to do ImageSourceModule.fromNativeSource(contact.photo).toBase64String("png")
and ImageSourceModule.fromNativeSource(contact.photo.ios).toBase64String("png")
this will lead to an error setNativeSource is not UIImage

Performance is slow

I try on the real device galaxy note 2. It take 17s to get 100 contact records. I thought and expect to be quick but it is not. Any idea why it is extremely slow. Implementing directly from Android take less than 1 second to get 100 contact.

What is the problem and any advice how to improve the speed to get the device contacts.

Unable to getAllContacts on iOS 13

It seems that something is broken when using this library on iOS 13. The permission request pops up, and there are no error messages. But the response is always an empty list.

Same code on iOS 12 or below works fine.

To reproduce

tns create contacts-test --template tns-template-hello-world-ng
cd contacts-test
tns info
✔ Getting NativeScript components versions information...
✔ Component nativescript has 6.2.0 version and is up to date.
✔ Component tns-core-modules has 6.2.0 version and is up to date.
✔ Component tns-android has 6.2.0 version and is up to date.
✔ Component tns-ios has 6.2.0 version and is up to date.
yarn add nativescript-contacts

add to Info.plist:

<key>NSContactsUsageDescription</key>
<string>Kindly provide permission to access contact on your device.</string>

add to items.component.ts

import { getAllContacts } from "nativescript-contacts";
<snip>
    ngOnInit(): void {
        this.items = this.itemService.getItems();
        getAllContacts().then(contacts => console.log(`got ${contacts.data.length} contacts`));
    }

Open multiple emulators from iOS 10 to iOS 13.

tns run ios --emulator

See that contacts.data.length is 0 for iOS 13.

Webpack build issue on Angular project

When building an {N}+Angular project with webpack, I get the following error:

Module not found: Error: Can't resolve 'nativescript-worker-loader'

My NativeScript worker loader is configured according to the docs for the project, and workers within the project have no issues.

I was able to resolve this issue by just adding nativescript-dev-webpack as a dev dependency to this plugin.

(PR on the way)

Console.dump deprecated in NativeScript 3.0

console.dump has been deprecated from NativeScript 3.0 in favor of console.dir, you can fix this? i have the next error :

file:///app/tns_modules/nativescript-contacts/index.js:83:25: JS ERROR TypeError: console.dump is not a function. (In 'console.dump(e)', 'console.dump' is undefined)

Thanks!

ViewHierarchy error on iOS

When selecting a contact, I would like to open a custom view if there are multiple addresses registered for that contact.

So the code looks like this

getContact().then((result: GetContactResult) => {
      if (result.response === 'selected') {
          if (result.data.postalAddresses != null && result.data.postalAddresses.length > 1) {
             openMultipleAddressPopup(result.data);
          } else {
            ...
      }

On iOS, this always throws an exception, because the contact frame is not completely closed when showing my custom view. A dirty workaround is to put a timeout() to ensure that the contact frame is correctly closed, but this is really not a good solution. Putting a value of 1 sec for the timeout seems to make the whole thing work 90% of the time, which is clearly insufficient.

So it would be good to be notified when the contact window closed. If I'm not wrong, this is a native functionality of iOS (when you open the contact window, you can pass a callback that will be called when the frame is completely closed).

This Stackoverflow thread explains this problem quite well:
https://stackoverflow.com/questions/55769425/nativescript-javascript-modal-dialog-fails-with-viewhierarchy-error-on-ios

Plugin conflits when using nativescript-admob and nativescript-telerik-ui

nativescript-contacts plugin alone with nativescript-admob or it alone with nativescript-telerik-ui pass on build, but when I use it with both, the build get this error:

:buildMetadata
Exception in thread "main" java.lang.IllegalArgumentException: Class android.support.v7.appcompat.R$drawable conflict: /Users/macbook/Downloads/agua/platforms/android/build/intermediates/classes/admobNativescript-telerik-ui/debug and /Users/macbook/Downloads/agua/platforms/android/build/intermediates/classes/admobNativescript-contactsNativescript-telerik-ui/debug
    at com.telerik.metadata.ClassRepo.cacheJarFile(ClassRepo.java:21)
    at com.telerik.metadata.Builder.build(Builder.java:41)
    at com.telerik.metadata.Generator.main(Generator.java:44)
:buildMetadata FAILED

Question: Android Cursor

Since we are passing back native objects, won't passing back the cursor cause a memory leak since we are not closing it?

Should we be thinking of some other way to pass back a native android object other than the cursor that way we can ensure it is closed?

Input appreciated!

getAllContacts only returns contacts the first time

After updating to NativeScript 6.5 and tns-android 6.5.0, getAllContacts(["name"]) only returns contacts the first time it's called.

I tested some older versions, and for NativeScript 6.5 and tns-android 6.4.0, the same code works well.

But for NativeScript 6.5 and tns-android 6.4.1 it fails again..

Android: Permission denial reading

Hi,
on my android testphone - were it worked until now - i get this exception:

Error: java.lang.SecurityException: Permission Denial: reading
com.android.providers.contacts.ContactsProvider2 uri content://com.android.contacts/display_photo/2 from pid=26745, uid=10441 requires android.PERMISSION.READ_CONTACTS or grantUriPermission()

Permissions are not added to AndroidManifest.xml, if i add them by hand i still get the same error.

Also tried these suggstions: http://stackoverflow.com/questions/8104776/permission-read-contacts-does-not-seem-to-work - no success

Any hints?

Possibly corrupting contacts?

I'm working on a (dumb) little demo where I get all contacts w/o pictures and then "fix" them by adding a picture from the PlaceKitten service. My demo currently gets all contacts, filters by those w/o pictures, and at this point I stopped and wrote some temp code to test on one contact at a time.

In my test, I saw that it worked, the contact now had a kitten picture, but I noticed something odd. While the contact showed up in my phone's contacts list, I could no longer search for them.

I've now seen this twice in my testing. In my second test, I confirmed a search for the contact worked, I then modified the contact, and now I can't "find" them anymore.

Here's part of the code in question (and it's rough, was going to clean it up more):

    created() {
        this.status = 'Loading up your contacts to find those missing a picture - please stand by!';

        permissions.requestPermissions([android.Manifest.permission.READ_CONTACTS, android.Manifest.permission.WRITE_CONTACTS], 'I need these permissions to work with your contact.')
            .then(() => {

                var contactFields = ['name','nickname','photo'];
                contacts.getAllContacts(contactFields).then(
                    args => {

                        //get contacts w/o a picture AND with a name
                        let fixableContacts = args.data.filter(c => {
                            if(c.photo) return false;
                            if(!c.nickname && !c.name.family) return false;
                            return true;
                        });
    
                        //set a proper name value - we filtered out no name folks above
                        fixableContacts = fixableContacts.map(c => {
                            if(c.nickname) c.fixedName = c.nickname;
                            else if(c.name.family) c.fixedName = c.name.given + ' ' + c.name.family;
                            return c;
                        });

    console.log(fixableContacts[0]);
    
                        this.status = `You have ${fixableContacts.length} named contacts without pictures...`;
                        this.contacts = fixableContacts;
                        this.readyToFix = true;

                        // temp test
                        if(fixableContacts[0].fixedName === 'Susan Oliver') {
                            console.log('testing on zoe');
                            imageSource
                                .fromUrl(getRandomCatURL())
                                .then(function(src) {
                                    console.log('i got the src');
                                    fixableContacts[0].photo = src;
                                    fixableContacts[0].save();
                                    console.log('IT WORKED');
                                });
                        
                        }
                    },
                    err => {
                        console.log("Error: " + err);
                    }
                );

            })
            .catch(e => {
                console.log('error in perms thing',e);
            });


    }

The only thing I can think of is that I modify the contacts to add a name property I can use in my display. Would adding a new field to a contact somehow break it?

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.