@@ -81,6 +81,11 @@ @interface FIRAuthModernAppDelegate : NSObject <UIApplicationDelegate>
81
81
*/
82
82
@property (nonatomic , copy , nullable ) NSData *deviceTokenReceived;
83
83
84
+ /* * @var tokenErrorReceived
85
+ @brief The last token error received, if any.
86
+ */
87
+ @property (nonatomic , copy , nullable ) NSError *tokenErrorReceived;
88
+
84
89
/* * @var notificationReceived
85
90
@brief The last notification received, if any.
86
91
*/
@@ -100,6 +105,11 @@ - (void)application:(UIApplication *)application
100
105
self.deviceTokenReceived = deviceToken;
101
106
}
102
107
108
+ - (void )application : (UIApplication *)application
109
+ didFailToRegisterForRemoteNotificationsWithError : (nonnull NSError *)error {
110
+ self.tokenErrorReceived = error;
111
+ }
112
+
103
113
- (void )application : (UIApplication *)application
104
114
didReceiveRemoteNotification : (NSDictionary *)userInfo
105
115
fetchCompletionHandler : (void (^)(UIBackgroundFetchResult))completionHandler {
@@ -153,6 +163,11 @@ @implementation FIRAuthAppDelegateProxyTests {
153
163
*/
154
164
NSData *_deviceToken;
155
165
166
+ /* * @var _error
167
+ @brief The fake error for testing.
168
+ */
169
+ NSError *_error;
170
+
156
171
/* * @var _notification
157
172
@brief The fake notification for testing.
158
173
*/
@@ -173,6 +188,7 @@ - (void)setUp {
173
188
[super setUp ];
174
189
_mockApplication = OCMClassMock ([UIApplication class ]);
175
190
_deviceToken = [@" asdf" dataUsingEncoding: NSUTF8StringEncoding];
191
+ _error = [NSError errorWithDomain: @" FakeError" code: 12345 userInfo: nil ];
176
192
_notification = @{ @" zxcv" : @1234 };
177
193
_url = [NSURL URLWithString: @" https://abc.def/ghi" ];
178
194
_isIOS9orLater = [[[UIDevice currentDevice ] systemVersion ] doubleValue ] >= 9.0 ;
@@ -261,6 +277,8 @@ - (void)testEmptyDelegateOneHandler {
261
277
// Verify certain methods are swizzled while others are not.
262
278
XCTAssertTrue ([delegate respondsToSelector:
263
279
@selector (application:didRegisterForRemoteNotificationsWithDeviceToken: )]);
280
+ XCTAssertTrue ([delegate respondsToSelector:
281
+ @selector (application:didFailToRegisterForRemoteNotificationsWithError: )]);
264
282
XCTAssertTrue ([delegate respondsToSelector:
265
283
@selector (application:didReceiveRemoteNotification:fetchCompletionHandler: )]);
266
284
XCTAssertFalse ([delegate respondsToSelector:
@@ -288,6 +306,12 @@ - (void)testEmptyDelegateOneHandler {
288
306
didRegisterForRemoteNotificationsWithDeviceToken: _deviceToken];
289
307
OCMVerifyAll (mockHandler);
290
308
309
+ // Verify `application:didFailToRegisterForRemoteNotificationsWithError:` is handled.
310
+ OCMExpect ([mockHandler handleAPNSTokenError: _error]);
311
+ [delegate application: _mockApplication
312
+ didFailToRegisterForRemoteNotificationsWithError: _error];
313
+ OCMVerifyAll (mockHandler);
314
+
291
315
// Verify `application:didReceiveRemoteNotification:fetchCompletionHandler:` is handled.
292
316
OCMExpect ([mockHandler canHandleNotification: _notification]).andReturn (YES );
293
317
__block BOOL fetchCompletionHandlerCalled = NO ;
@@ -323,6 +347,8 @@ - (void)testEmptyDelegateOneHandler {
323
347
// Verify nothing bad happens after the handler is released.
324
348
[delegate application: _mockApplication
325
349
didRegisterForRemoteNotificationsWithDeviceToken: _deviceToken];
350
+ [delegate application: _mockApplication
351
+ didFailToRegisterForRemoteNotificationsWithError: _error];
326
352
[delegate application: _mockApplication
327
353
didReceiveRemoteNotification: _notification
328
354
fetchCompletionHandler: ^(UIBackgroundFetchResult result) {
@@ -374,6 +400,8 @@ - (void)testLegacyDelegateTwoHandlers {
374
400
// Verify certain methods are swizzled while others are not.
375
401
XCTAssertTrue ([delegate respondsToSelector:
376
402
@selector (application:didRegisterForRemoteNotificationsWithDeviceToken: )]);
403
+ XCTAssertTrue ([delegate respondsToSelector:
404
+ @selector (application:didFailToRegisterForRemoteNotificationsWithError: )]);
377
405
XCTAssertFalse ([delegate respondsToSelector:
378
406
@selector (application:didReceiveRemoteNotification:fetchCompletionHandler: )]);
379
407
XCTAssertTrue ([delegate respondsToSelector:
@@ -401,6 +429,14 @@ - (void)testLegacyDelegateTwoHandlers {
401
429
OCMVerifyAll (mockHandler1);
402
430
OCMVerifyAll (mockHandler2);
403
431
432
+ // Verify `application:didFailToRegisterForRemoteNotificationsWithError:` is handled.
433
+ OCMExpect ([mockHandler1 handleAPNSTokenError: _error]);
434
+ OCMExpect ([mockHandler2 handleAPNSTokenError: _error]);
435
+ [delegate application: _mockApplication
436
+ didFailToRegisterForRemoteNotificationsWithError: _error];
437
+ OCMVerifyAll (mockHandler1);
438
+ OCMVerifyAll (mockHandler2);
439
+
404
440
// Verify `application:didReceiveRemoteNotification:fetchCompletionHandler:` is handled.
405
441
OCMExpect ([mockHandler1 canHandleNotification: _notification]).andReturn (YES );
406
442
// handler2 shouldn't been invoked because it is already handled by handler1.
@@ -431,6 +467,12 @@ - (void)testLegacyDelegateTwoHandlers {
431
467
didRegisterForRemoteNotificationsWithDeviceToken: _deviceToken];
432
468
OCMVerifyAll (mockHandler1);
433
469
470
+ // Verify `application:didFailToRegisterForRemoteNotificationsWithError:` is handled.
471
+ OCMExpect ([mockHandler1 handleAPNSTokenError: _error]);
472
+ [delegate application: _mockApplication
473
+ didFailToRegisterForRemoteNotificationsWithError: _error];
474
+ OCMVerifyAll (mockHandler1);
475
+
434
476
// Verify `application:didReceiveRemoteNotification:fetchCompletionHandler:` is NOT handled.
435
477
OCMExpect ([mockHandler1 canHandleNotification: _notification]).andReturn (NO );
436
478
[delegate application: _mockApplication didReceiveRemoteNotification: _notification];
@@ -457,6 +499,8 @@ - (void)testLegacyDelegateTwoHandlers {
457
499
// Verify the delegate still works after all handlers are released.
458
500
[delegate application: _mockApplication
459
501
didRegisterForRemoteNotificationsWithDeviceToken: _deviceToken];
502
+ [delegate application: _mockApplication
503
+ didFailToRegisterForRemoteNotificationsWithError: _error];
460
504
[delegate application: _mockApplication didReceiveRemoteNotification: _notification];
461
505
XCTAssertEqualObjects (delegate.notificationReceived , _notification);
462
506
delegate.notificationReceived = nil ;
@@ -504,6 +548,8 @@ - (void)testModernDelegateWithUnaffectedInstance {
504
548
// Verify certain methods are swizzled while others are not.
505
549
XCTAssertTrue ([delegate respondsToSelector:
506
550
@selector (application:didRegisterForRemoteNotificationsWithDeviceToken: )]);
551
+ XCTAssertTrue ([delegate respondsToSelector:
552
+ @selector (application:didFailToRegisterForRemoteNotificationsWithError: )]);
507
553
XCTAssertTrue ([delegate respondsToSelector:
508
554
@selector (application:didReceiveRemoteNotification:fetchCompletionHandler: )]);
509
555
XCTAssertFalse ([delegate respondsToSelector:
@@ -532,6 +578,14 @@ - (void)testModernDelegateWithUnaffectedInstance {
532
578
XCTAssertEqualObjects (delegate.deviceTokenReceived , _deviceToken);
533
579
delegate.deviceTokenReceived = nil ;
534
580
581
+ // Verify `application:didFailToRegisterForRemoteNotificationsWithError:` is handled.
582
+ OCMExpect ([mockHandler handleAPNSTokenError: _error]);
583
+ [delegate application: _mockApplication
584
+ didFailToRegisterForRemoteNotificationsWithError: _error];
585
+ OCMVerifyAll (mockHandler);
586
+ XCTAssertEqualObjects (delegate.tokenErrorReceived , _error);
587
+ delegate.tokenErrorReceived = nil ;
588
+
535
589
// Verify `application:didReceiveRemoteNotification:fetchCompletionHandler:` is handled.
536
590
OCMExpect ([mockHandler canHandleNotification: _notification]).andReturn (YES );
537
591
__block BOOL fetchCompletionHandlerCalled = NO ;
@@ -565,6 +619,10 @@ - (void)testModernDelegateWithUnaffectedInstance {
565
619
didRegisterForRemoteNotificationsWithDeviceToken: _deviceToken];
566
620
XCTAssertEqualObjects (unaffectedDelegate.deviceTokenReceived , _deviceToken);
567
621
unaffectedDelegate.deviceTokenReceived = nil ;
622
+ [unaffectedDelegate application: _mockApplication
623
+ didFailToRegisterForRemoteNotificationsWithError: _error];
624
+ XCTAssertEqualObjects (unaffectedDelegate.tokenErrorReceived , _error);
625
+ unaffectedDelegate.tokenErrorReceived = nil ;
568
626
fetchCompletionHandlerCalled = NO ;
569
627
[unaffectedDelegate application: _mockApplication
570
628
didReceiveRemoteNotification: _notification
@@ -590,6 +648,10 @@ - (void)testModernDelegateWithUnaffectedInstance {
590
648
didRegisterForRemoteNotificationsWithDeviceToken: _deviceToken];
591
649
XCTAssertEqualObjects (delegate.deviceTokenReceived , _deviceToken);
592
650
delegate.deviceTokenReceived = nil ;
651
+ [delegate application: _mockApplication
652
+ didFailToRegisterForRemoteNotificationsWithError: _error];
653
+ XCTAssertEqualObjects (delegate.tokenErrorReceived , _error);
654
+ delegate.tokenErrorReceived = nil ;
593
655
__block BOOL fetchCompletionHandlerCalled = NO ;
594
656
[delegate application: _mockApplication
595
657
didReceiveRemoteNotification: _notification
@@ -615,7 +677,11 @@ - (void)testModernDelegateWithUnaffectedInstance {
615
677
didRegisterForRemoteNotificationsWithDeviceToken: _deviceToken];
616
678
XCTAssertEqualObjects (delegate.deviceTokenReceived , _deviceToken);
617
679
delegate.deviceTokenReceived = nil ;
618
- __block BOOL fetchCompletionHandlerCalled = NO ;
680
+ [delegate application: _mockApplication
681
+ didFailToRegisterForRemoteNotificationsWithError: _error];
682
+ XCTAssertEqualObjects (delegate.tokenErrorReceived , _error);
683
+ delegate.tokenErrorReceived = nil ;
684
+ __block BOOL fetchCompletionHandlerCalled = NO ;
619
685
[delegate application: _mockApplication
620
686
didReceiveRemoteNotification: _notification
621
687
fetchCompletionHandler: ^(UIBackgroundFetchResult result) {
0 commit comments