@@ -30,27 +30,34 @@ @implementation RNVoipPushNotificationManager
30
30
static NSString *_lastVoipToken = @" " ;
31
31
static NSMutableDictionary <NSString *, RNVoipPushNotificationCompletion> *completionHandlers = nil ;
32
32
33
-
34
33
// =====
35
34
// ===== RN Module Configure and Override =====
36
35
// =====
37
36
37
+ -(instancetype ) init
38
+ {
39
+ return [[self class ] sharedInstance ];
40
+ }
38
41
39
- - (instancetype )init
42
+ -(instancetype ) initPrivate
40
43
{
41
44
if (self = [super init ]) {
42
45
_delayedEvents = [NSMutableArray array ];
43
46
}
47
+
44
48
return self;
45
49
}
46
50
47
- + (id )allocWithZone : (NSZone *)zone {
48
- static RNVoipPushNotificationManager *sharedInstance = nil ;
51
+ // Singletone implementation based on https://stackoverflow.com/q/5720029/3686678 and https://stackoverflow.com/a/7035136/3686678
52
+ +(instancetype ) sharedInstance
53
+ {
54
+ static RNVoipPushNotificationManager *sharedVoipPushManager = nil ;
49
55
static dispatch_once_t onceToken;
50
56
dispatch_once (&onceToken, ^{
51
- sharedInstance = [super allocWithZone: zone ];
57
+ sharedVoipPushManager = [[ self alloc ] initPrivate ];
52
58
});
53
- return sharedInstance;
59
+
60
+ return sharedVoipPushManager;
54
61
}
55
62
56
63
// --- clean observer and completionHandlers when app close
@@ -126,7 +133,7 @@ + (void)voipRegistration
126
133
#ifdef DEBUG
127
134
RCTLog (@" [RNVoipPushNotificationManager] voipRegistration is already registered. return _lastVoipToken = %@ " , _lastVoipToken);
128
135
#endif
129
- RNVoipPushNotificationManager *voipPushManager = [RNVoipPushNotificationManager allocWithZone: nil ];
136
+ RNVoipPushNotificationManager *voipPushManager = [RNVoipPushNotificationManager sharedInstance ];
130
137
[voipPushManager sendEventWithNameWrapper: RNVoipPushRemoteNotificationsRegisteredEvent body: _lastVoipToken];
131
138
} else {
132
139
_isVoipRegistered = YES ;
@@ -164,7 +171,7 @@ + (void)didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSStr
164
171
165
172
_lastVoipToken = [hexString copy ];
166
173
167
- RNVoipPushNotificationManager *voipPushManager = [RNVoipPushNotificationManager allocWithZone: nil ];
174
+ RNVoipPushNotificationManager *voipPushManager = [RNVoipPushNotificationManager sharedInstance ];
168
175
[voipPushManager sendEventWithNameWrapper: RNVoipPushRemoteNotificationsRegisteredEvent body: _lastVoipToken];
169
176
}
170
177
@@ -175,7 +182,7 @@ + (void)didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSSt
175
182
RCTLog (@" [RNVoipPushNotificationManager] didReceiveIncomingPushWithPayload payload.dictionaryPayload = %@ , type = %@ " , payload.dictionaryPayload , type);
176
183
#endif
177
184
178
- RNVoipPushNotificationManager *voipPushManager = [RNVoipPushNotificationManager allocWithZone: nil ];
185
+ RNVoipPushNotificationManager *voipPushManager = [RNVoipPushNotificationManager sharedInstance ];
179
186
[voipPushManager sendEventWithNameWrapper: RNVoipPushRemoteNotificationReceivedEvent body: payload.dictionaryPayload];
180
187
}
181
188
0 commit comments