Skip to content

Commit c9e7c3d

Browse files
committed
fix: more robust observer null check
1 parent a20f602 commit c9e7c3d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

contacts.mm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <napi.h>
33

44
Napi::ThreadSafeFunction ts_fn;
5-
id observer;
5+
id observer = nil;
66

77
/***** HELPERS *****/
88

@@ -536,7 +536,7 @@ CNAuthorizationStatus AuthStatus() {
536536
Napi::Boolean SetupListener(const Napi::CallbackInfo &info) {
537537
Napi::Env env = info.Env();
538538

539-
if (observer) {
539+
if (observer != nil) {
540540
Napi::Error::New(env, "An observer is already observing")
541541
.ThrowAsJavaScriptException();
542542
return Napi::Boolean::New(env, false);
@@ -564,7 +564,7 @@ CNAuthorizationStatus AuthStatus() {
564564
Napi::Boolean RemoveListener(const Napi::CallbackInfo &info) {
565565
Napi::Env env = info.Env();
566566

567-
if (!observer) {
567+
if (observer == nil) {
568568
Napi::Error::New(env, "No observers are currently observing")
569569
.ThrowAsJavaScriptException();
570570
return Napi::Boolean::New(env, false);
@@ -576,8 +576,8 @@ CNAuthorizationStatus AuthStatus() {
576576
// Remove observer from the Notification Center.
577577
[[NSNotificationCenter defaultCenter] removeObserver:observer];
578578

579-
// Reset observer.
580-
observer = nullptr;
579+
// Reset observer to nil.
580+
observer = nil;
581581

582582
return Napi::Boolean::New(env, true);
583583
}

0 commit comments

Comments
 (0)