Skip to content

Commit dff2a98

Browse files
committed
move register notification subscription into methods that relies on it.
1 parent e1466da commit dff2a98

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

Libraries/PushNotificationIOS/RCTPushNotificationManager.m

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,17 @@ - (void)startObserving
142142
selector:@selector(handleRemoteNotificationReceived:)
143143
name:RCTRemoteNotificationReceived
144144
object:nil];
145+
[self startObservingRegisteredNotifications];
146+
}
147+
148+
149+
150+
- (void)startObservingRegisteredNotifications
151+
{
152+
[[NSNotificationCenter defaultCenter] addObserver:self
153+
selector:@selector(handleRegisterUserNotificationSettings:)
154+
name:RCTRegisterUserNotificationSettings
155+
object:nil];
145156
[[NSNotificationCenter defaultCenter] addObserver:self
146157
selector:@selector(handleRemoteNotificationsRegistered:)
147158
name:RCTRemoteNotificationsRegistered
@@ -150,15 +161,19 @@ - (void)startObserving
150161
selector:@selector(handleRemoteNotificationRegistrationError:)
151162
name:RCTErrorRemoteNotificationRegistrationFailed
152163
object:nil];
153-
[[NSNotificationCenter defaultCenter] addObserver:self
154-
selector:@selector(handleRegisterUserNotificationSettings:)
155-
name:RCTRegisterUserNotificationSettings
156-
object:nil];
157164
}
158165

159-
- (void)stopObserving
166+
- (void)stopObservingRegisteredNotifications
160167
{
161-
[[NSNotificationCenter defaultCenter] removeObserver:self];
168+
[[NSNotificationCenter defaultCenter] removeObserver:self
169+
name:RCTErrorRemoteNotificationRegistrationFailed
170+
object:nil];
171+
[[NSNotificationCenter defaultCenter] removeObserver:self
172+
name:RCTRegisterUserNotificationSettings
173+
object:nil];
174+
[[NSNotificationCenter defaultCenter] removeObserver:self
175+
name:RCTRemoteNotificationsRegistered
176+
object:nil];
162177
}
163178

164179
- (NSArray<NSString *> *)supportedEvents
@@ -249,6 +264,7 @@ - (void)handleRemoteNotificationReceived:(NSNotification *)notification
249264
- (void)handleRemoteNotificationsRegistered:(NSNotification *)notification
250265
{
251266
[self sendEventWithName:@"remoteNotificationsRegistered" body:notification.userInfo];
267+
[self stopObservingRegisteredNotifications];
252268
}
253269

254270
- (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification
@@ -260,6 +276,7 @@ - (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification
260276
@"details": error.userInfo,
261277
};
262278
[self sendEventWithName:@"remoteNotificationRegistrationError" body:errorDetails];
279+
[self stopObservingRegisteredNotifications];
263280
}
264281

265282
- (void)handleRegisterUserNotificationSettings:(NSNotification *)notification
@@ -319,6 +336,7 @@ - (void)handleRegisterUserNotificationSettings:(NSNotification *)notification
319336
return;
320337
}
321338

339+
[self startObservingRegisteredNotifications];
322340
_requestPermissionsResolveBlock = resolve;
323341

324342
UIUserNotificationType types = UIUserNotificationTypeNone;

0 commit comments

Comments
 (0)