Skip to content

Fix stopObserving on reload issue #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions ios/RNVoipPushNotification/RNVoipPushNotificationManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,34 @@ @implementation RNVoipPushNotificationManager
static NSString *_lastVoipToken = @"";
static NSMutableDictionary<NSString *, RNVoipPushNotificationCompletion> *completionHandlers = nil;


// =====
// ===== RN Module Configure and Override =====
// =====

-(instancetype) init
{
return [[self class] sharedInstance];
}

- (instancetype)init
-(instancetype) initPrivate
{
if (self = [super init]) {
_delayedEvents = [NSMutableArray array];
}

return self;
}

+ (id)allocWithZone:(NSZone *)zone {
static RNVoipPushNotificationManager *sharedInstance = nil;
// Singletone implementation based on https://stackoverflow.com/q/5720029/3686678 and https://stackoverflow.com/a/7035136/3686678
+(instancetype) sharedInstance
{
static RNVoipPushNotificationManager *sharedVoipPushManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [super allocWithZone:zone];
sharedVoipPushManager = [[self alloc] initPrivate];
});
return sharedInstance;

return sharedVoipPushManager;
}

// --- clean observer and completionHandlers when app close
Expand Down Expand Up @@ -94,12 +101,6 @@ - (void)startObserving
}
}

- (void)stopObserving
{
_hasListeners = NO;
}



// =====
// ===== Class Method =====
Expand All @@ -126,7 +127,7 @@ + (void)voipRegistration
#ifdef DEBUG
RCTLog(@"[RNVoipPushNotificationManager] voipRegistration is already registered. return _lastVoipToken = %@", _lastVoipToken);
#endif
RNVoipPushNotificationManager *voipPushManager = [RNVoipPushNotificationManager allocWithZone: nil];
RNVoipPushNotificationManager *voipPushManager = [RNVoipPushNotificationManager sharedInstance];
[voipPushManager sendEventWithNameWrapper:RNVoipPushRemoteNotificationsRegisteredEvent body:_lastVoipToken];
} else {
_isVoipRegistered = YES;
Expand Down Expand Up @@ -164,7 +165,7 @@ + (void)didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSStr

_lastVoipToken = [hexString copy];

RNVoipPushNotificationManager *voipPushManager = [RNVoipPushNotificationManager allocWithZone: nil];
RNVoipPushNotificationManager *voipPushManager = [RNVoipPushNotificationManager sharedInstance];
[voipPushManager sendEventWithNameWrapper:RNVoipPushRemoteNotificationsRegisteredEvent body:_lastVoipToken];
}

Expand All @@ -175,7 +176,7 @@ + (void)didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSSt
RCTLog(@"[RNVoipPushNotificationManager] didReceiveIncomingPushWithPayload payload.dictionaryPayload = %@, type = %@", payload.dictionaryPayload, type);
#endif

RNVoipPushNotificationManager *voipPushManager = [RNVoipPushNotificationManager allocWithZone: nil];
RNVoipPushNotificationManager *voipPushManager = [RNVoipPushNotificationManager sharedInstance];
[voipPushManager sendEventWithNameWrapper:RNVoipPushRemoteNotificationReceivedEvent body:payload.dictionaryPayload];
}

Expand Down