@@ -287,6 +287,14 @@ static void AppDelegateApplicationDidBecomeActive(id self, SEL selector_value,
287287 if (app_delegate_application_did_become_active) {
288288 ((util::AppDelegateApplicationDidBecomeActiveFunc)app_delegate_application_did_become_active)(
289289 self, selector_value, application);
290+ } else if ([self methodForSelector: @selector (forwardInvocation: )] !=
291+ [NSObject instanceMethodForSelector: @selector (forwardInvocation: )]) {
292+ NSMethodSignature *signature = [[self class ] instanceMethodSignatureForSelector: selector_value];
293+ NSInvocation *invocation = [NSInvocation invocationWithMethodSignature: signature];
294+ [invocation setSelector: selector_value];
295+ [invocation setTarget: self ];
296+ [invocation setArgument: &application atIndex: 2 ];
297+ [self forwardInvocation: invocation];
290298 }
291299}
292300
@@ -298,6 +306,14 @@ static void AppDelegateApplicationDidEnterBackground(id self, SEL selector_value
298306 if (app_delegate_application_did_enter_background) {
299307 ((util::AppDelegateApplicationDidEnterBackgroundFunc)
300308 app_delegate_application_did_enter_background)(self, selector_value, application);
309+ } else if ([self methodForSelector: @selector (forwardInvocation: )] !=
310+ [NSObject instanceMethodForSelector: @selector (forwardInvocation: )]) {
311+ NSMethodSignature *signature = [[self class ] instanceMethodSignatureForSelector: selector_value];
312+ NSInvocation *invocation = [NSInvocation invocationWithMethodSignature: signature];
313+ [invocation setSelector: selector_value];
314+ [invocation setTarget: self ];
315+ [invocation setArgument: &application atIndex: 2 ];
316+ [self forwardInvocation: invocation];
301317 }
302318 if (MessagingIsInitialized ()) {
303319 LogInfo (" FCM: Disconnect FCM service" );
@@ -341,6 +357,15 @@ static void AppDelegateApplicationDidRegisterForRemoteNotificationsWithDeviceTok
341357 ((util::AppDelegateApplicationDidRegisterForRemoteNotificationsWithDeviceTokenFunc)
342358 app_delegate_application_did_register_for_remote_notifications_with_device_token)(
343359 self, selector_value, application, deviceToken);
360+ } else if ([self methodForSelector: @selector (forwardInvocation: )] !=
361+ [NSObject instanceMethodForSelector: @selector (forwardInvocation: )]) {
362+ NSMethodSignature *signature = [[self class ] instanceMethodSignatureForSelector: selector_value];
363+ NSInvocation *invocation = [NSInvocation invocationWithMethodSignature: signature];
364+ [invocation setSelector: selector_value];
365+ [invocation setTarget: self ];
366+ [invocation setArgument: &application atIndex: 2 ];
367+ [invocation setArgument: &deviceToken atIndex: 3 ];
368+ [self forwardInvocation: invocation];
344369 }
345370}
346371
@@ -358,6 +383,15 @@ static void AppDelegateApplicationDidFailToRegisterForRemoteNotificationsWithErr
358383 ((util::AppDelegateApplicationDidFailToRegisterForRemoteNotificationsWithErrorFunc)
359384 app_delegate_application_did_fail_to_register_for_remote_notifications_with_error)(
360385 self, selector_value, application, error);
386+ } else if ([self methodForSelector: @selector (forwardInvocation: )] !=
387+ [NSObject instanceMethodForSelector: @selector (forwardInvocation: )]) {
388+ NSMethodSignature *signature = [[self class ] instanceMethodSignatureForSelector: selector_value];
389+ NSInvocation *invocation = [NSInvocation invocationWithMethodSignature: signature];
390+ [invocation setSelector: selector_value];
391+ [invocation setTarget: self ];
392+ [invocation setArgument: &application atIndex: 2 ];
393+ [invocation setArgument: &error atIndex: 3 ];
394+ [self forwardInvocation: invocation];
361395 }
362396}
363397
@@ -475,7 +509,7 @@ static BOOL AppDelegateApplicationDidFinishLaunchingWithOptions(id self, SEL sel
475509 NSDictionary *launch_options) {
476510 // Set up Messaging on iOS 10, if possible.
477511 Class notification_center_class = NSClassFromString (@" UNUserNotificationCenter" );
478- if (notification_center_class) {
512+ if (notification_center_class && application ) {
479513 LogInfo (" Setting up iOS 10 message delegate." );
480514
481515 // Cache the existing delegate if one exists it so we can pass along messages when needed.
@@ -499,6 +533,19 @@ static BOOL AppDelegateApplicationDidFinishLaunchingWithOptions(id self, SEL sel
499533 return ((util::AppDelegateApplicationDidFinishLaunchingWithOptionsFunc)
500534 app_delegate_application_did_finish_launching_with_options)(
501535 self, selector_value, application, launch_options);
536+ } else if ([self methodForSelector: @selector (forwardInvocation: )] !=
537+ [NSObject instanceMethodForSelector: @selector (forwardInvocation: )]) {
538+ NSMethodSignature *signature = [[self class ] instanceMethodSignatureForSelector: selector_value];
539+ NSInvocation *invocation = [NSInvocation invocationWithMethodSignature: signature];
540+ [invocation setSelector: selector_value];
541+ [invocation setTarget: self ];
542+ [invocation setArgument: &application atIndex: 2 ];
543+ [invocation setArgument: &launch_options atIndex: 3 ];
544+ [self forwardInvocation: invocation];
545+ // Read the return value from the invocation.
546+ BOOL ret = NO ;
547+ [invocation getReturnValue: &ret];
548+ return ret;
502549 }
503550 return NO ;
504551}
@@ -525,6 +572,15 @@ static void AppDelegateApplicationDidReceiveRemoteNotification(id self, SEL sele
525572 ((util::AppDelegateApplicationDidReceiveRemoteNotificationFunc)
526573 app_delegate_application_did_receive_remote_notification)(self, selector_value,
527574 application, user_info);
575+ } else if ([self methodForSelector: @selector (forwardInvocation: )] !=
576+ [NSObject instanceMethodForSelector: @selector (forwardInvocation: )]) {
577+ NSMethodSignature *signature = [[self class ] instanceMethodSignatureForSelector: selector_value];
578+ NSInvocation *invocation = [NSInvocation invocationWithMethodSignature: signature];
579+ [invocation setSelector: selector_value];
580+ [invocation setTarget: self ];
581+ [invocation setArgument: &application atIndex: 2 ];
582+ [invocation setArgument: &user_info atIndex: 3 ];
583+ [self forwardInvocation: invocation];
528584 }
529585}
530586
@@ -550,6 +606,16 @@ static void AppDelegateApplicationDidReceiveRemoteNotificationFetchCompletionHan
550606 ((util::AppDelegateApplicationDidReceiveRemoteNotificationFetchCompletionHandlerFunc)
551607 app_delegate_application_did_receive_remote_notification_fetch_completion_handler)(
552608 self, selector_value, application, user_info, handler);
609+ } else if ([self methodForSelector: @selector (forwardInvocation: )] !=
610+ [NSObject instanceMethodForSelector: @selector (forwardInvocation: )]) {
611+ NSMethodSignature *signature = [[self class ] instanceMethodSignatureForSelector: selector_value];
612+ NSInvocation *invocation = [NSInvocation invocationWithMethodSignature: signature];
613+ [invocation setSelector: selector_value];
614+ [invocation setTarget: self ];
615+ [invocation setArgument: &application atIndex: 2 ];
616+ [invocation setArgument: &user_info atIndex: 3 ];
617+ [invocation setArgument: &handler atIndex: 4 ];
618+ [self forwardInvocation: invocation];
553619 } else {
554620 // TODO(smiles): We should determine whether the entire message is sent to this notification
555621 // method, if not this is clearly wrong and will need to download the rest of the message.
0 commit comments