File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed
Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change 55Napi::ThreadSafeFunction ts_fn;
66id observer = nil ;
77
8+ Napi::Reference<Napi::Array> contacts_ref;
9+
810/* **** HELPERS *****/
911
1012// Dummy value to pass into function parameter for ThreadSafeFunction.
@@ -493,6 +495,9 @@ CNAuthorizationStatus AuthStatus() {
493495 if (AuthStatus () != CNAuthorizationStatusAuthorized)
494496 return Napi::Array::New (env);
495497
498+ if (!contacts_ref.IsEmpty ())
499+ return contacts_ref.Value ();
500+
496501 CNContactStore *addressBook = [[CNContactStore alloc ] init ];
497502 Napi::Array extra_keys = info[0 ].As <Napi::Array>();
498503
@@ -536,6 +541,8 @@ CNAuthorizationStatus AuthStatus() {
536541 contacts[i] = CreateContact (env, cncontact);
537542 }
538543
544+ contacts_ref = Napi::Persistent (contacts);
545+
539546 return contacts;
540547}
541548
@@ -647,6 +654,7 @@ CNAuthorizationStatus AuthStatus() {
647654 object: nil
648655 queue: [NSOperationQueue mainQueue ]
649656 usingBlock: ^(NSNotification *note) {
657+ contacts_ref.Reset ();
650658 auto callback = [](Napi::Env env, Napi::Function js_cb,
651659 const char *value) {
652660 js_cb.Call ({Napi::String::New (env, value)});
You can’t perform that action at this time.
0 commit comments