@@ -131,7 +131,9 @@ - (instancetype)initWithDelegate:(id<FIRMessagingClientDelegate>)delegate
131
131
}
132
132
133
133
- (void )teardown {
134
- FIRMessagingLoggerDebug (kFIRMessagingMessageCodeClient000 , @" " );
134
+ if (![NSThread isMainThread ]) {
135
+ FIRMessagingLoggerDebug (kFIRMessagingMessageCodeClient000 , @" FIRMessagingClient should be called from main thread only." );
136
+ }
135
137
self.stayConnected = NO ;
136
138
137
139
// Clear all the handlers
@@ -140,9 +142,8 @@ - (void)teardown {
140
142
[self .connection teardown ];
141
143
142
144
// Stop all subscription requests
143
- [self .registrar stopAllSubscriptionRequests ];
145
+ [self .registrar stopAllSubscriptionRequests ];
144
146
145
- _FIRMessagingDevAssert (self.connection .state == kFIRMessagingConnectionNotConnected , @" Did not disconnect" );
146
147
[NSObject cancelPreviousPerformRequestsWithTarget: self ];
147
148
148
149
[[NSNotificationCenter defaultCenter ] removeObserver: self ];
@@ -166,10 +167,7 @@ - (void)updateSubscriptionWithToken:(NSString *)token
166
167
options : (NSDictionary *)options
167
168
shouldDelete : (BOOL )shouldDelete
168
169
handler : (FIRMessagingTopicOperationCompletion)handler {
169
-
170
- _FIRMessagingDevAssert (handler != nil , @" Invalid handler to FIRMessaging subscribe" );
171
-
172
- FIRMessagingTopicOperationCompletion completion = ^void (NSError *error) {
170
+ FIRMessagingTopicOperationCompletion completion = ^void (NSError *error) {
173
171
if (error) {
174
172
FIRMessagingLoggerError (kFIRMessagingMessageCodeClient001 , @" Failed to subscribe to topic %@ " ,
175
173
error);
@@ -182,7 +180,9 @@ - (void)updateSubscriptionWithToken:(NSString *)token
182
180
@" Successfully subscribed to topic %@ " , topic);
183
181
}
184
182
}
185
- handler (error);
183
+ if (handler) {
184
+ handler (error);
185
+ }
186
186
};
187
187
188
188
if ([[FIRInstanceID instanceID ] tryToLoadValidCheckinInfo ]) {
@@ -316,8 +316,6 @@ - (void)disconnectWithTryToConnectLater:(BOOL)tryToConnectLater {
316
316
317
317
self.stayConnected = tryToConnectLater;
318
318
[self .connection signOut ];
319
- _FIRMessagingDevAssert (self.connection .state == kFIRMessagingConnectionNotConnected ,
320
- @" FIRMessaging connection did not disconnect" );
321
319
322
320
// since we can disconnect while still trying to establish the connection it's required to
323
321
// cancel all performSelectors else the object might be retained
@@ -421,8 +419,6 @@ - (void)setupConnectionAndConnect {
421
419
- (void )setupConnection {
422
420
NSString *host = FIRMessagingServerHost ();
423
421
NSUInteger port = FIRMessagingServerPort ();
424
- _FIRMessagingDevAssert ([host length ] > 0 && port != 0 , @" Invalid port or host" );
425
-
426
422
if (self.connection != nil ) {
427
423
// if there is an old connection, explicitly sign it off.
428
424
[self .connection signOut ];
@@ -447,17 +443,20 @@ - (void)tryToConnect {
447
443
[NSObject cancelPreviousPerformRequestsWithTarget: self
448
444
selector: @selector (tryToConnect )
449
445
object: nil ];
450
-
446
+ NSString *deviceAuthID = [FIRInstanceID instanceID ].deviceAuthID ;
447
+ NSString *secretToken = [FIRInstanceID instanceID ].secretToken ;
448
+ if (deviceAuthID.length == 0 || secretToken.length == 0 ||
449
+ !self.connection ) {
450
+ FIRMessagingLoggerWarn (kFIRMessagingMessageCodeClientInvalidState ,
451
+ @" Invalid state to connect, deviceAuthID: %@ , secretToken: %@ , connection state: %ld " ,
452
+ deviceAuthID, secretToken, (long )self.connection .state );
453
+ return ;
454
+ }
451
455
// Do not re-sign in if there is already a connection in progress.
452
456
if (self.connection .state != kFIRMessagingConnectionNotConnected ) {
453
457
return ;
454
458
}
455
459
456
- _FIRMessagingDevAssert ([FIRInstanceID instanceID ].deviceAuthID .length > 0 &&
457
- [FIRInstanceID instanceID ].secretToken .length > 0 &&
458
- self.connection != nil ,
459
- @" Invalid state cannot connect" );
460
-
461
460
self.connectRetryCount = MIN (kMaxRetryExponent , self.connectRetryCount + 1 );
462
461
[self performSelector: @selector (didConnectTimeout )
463
462
withObject: nil
@@ -466,9 +465,9 @@ - (void)tryToConnect {
466
465
}
467
466
468
467
- (void )didConnectTimeout {
469
- _FIRMessagingDevAssert (self.connection .state != kFIRMessagingConnectionSignedIn ,
470
- @" Invalid state for MCS connection" );
471
-
468
+ if (self.connection .state == kFIRMessagingConnectionSignedIn ) {
469
+ FIRMessagingLoggerWarn ( kFIRMessagingMessageCodeClientInvalidStateTimeout , @" Invalid state for connection timeout. " );
470
+ }
472
471
if (self.stayConnected ) {
473
472
[self .connection signOut ];
474
473
[self scheduleConnectRetry ];
0 commit comments