|
22 | 22 | #import "GoogleUtilities/Network/Public/GoogleUtilities/GULMutableDictionary.h"
|
23 | 23 |
|
24 | 24 | #import <objc/runtime.h>
|
| 25 | +#import <dispatch/group.h> |
25 | 26 |
|
26 | 27 | // Implementations need to be typed before calling the implementation directly to cast the
|
27 | 28 | // arguments and the return types correctly. Otherwise, it will crash the app.
|
@@ -881,18 +882,30 @@ - (void)application:(GULApplication *)application
|
881 | 882 | GULRealDidReceiveRemoteNotificationWithCompletionIMP
|
882 | 883 | didReceiveRemoteNotificationWithCompletionIMP =
|
883 | 884 | [didReceiveRemoteNotificationWithCompletionIMPPointer pointerValue];
|
884 |
| - |
| 885 | + |
| 886 | + dispatch_group_t __block callbackGroup = dispatch_group_create(); |
| 887 | + UIBackgroundFetchResult __block latestFetchResult = UIBackgroundFetchResultNoData; |
| 888 | + dispatch_group_notify(callbackGroup, dispatch_get_main_queue(), ^() { |
| 889 | + completionHandler(latestFetchResult); |
| 890 | + }); |
885 | 891 | // Notify interceptors.
|
886 | 892 | [GULAppDelegateSwizzler
|
887 | 893 | notifyInterceptorsWithMethodSelector:methodSelector
|
888 | 894 | callback:^(id<GULApplicationDelegate> interceptor) {
|
| 895 | + |
| 896 | + dispatch_group_enter(callbackGroup); |
| 897 | + void (^localCompletionHandler)(UIBackgroundFetchResult) = ^void (UIBackgroundFetchResult fetchResult){ |
| 898 | + latestFetchResult = fetchResult; |
| 899 | + dispatch_group_leave(callbackGroup); |
| 900 | + }; |
| 901 | + |
889 | 902 | NSInvocation *invocation = [GULAppDelegateSwizzler
|
890 | 903 | appDelegateInvocationForSelector:methodSelector];
|
891 | 904 | [invocation setTarget:interceptor];
|
892 | 905 | [invocation setSelector:methodSelector];
|
893 | 906 | [invocation setArgument:(void *)(&application) atIndex:2];
|
894 | 907 | [invocation setArgument:(void *)(&userInfo) atIndex:3];
|
895 |
| - [invocation setArgument:(void *)(&completionHandler) atIndex:4]; |
| 908 | + [invocation setArgument:(void *)(&localCompletionHandler) atIndex:4]; |
896 | 909 | [invocation invoke];
|
897 | 910 | }];
|
898 | 911 | // Call the real implementation if the real App Delegate has any.
|
|
0 commit comments