-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathAppsFlyerX+AppController.m
57 lines (44 loc) · 2 KB
/
AppsFlyerX+AppController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// AppController+AppsFlyerX_AppController.m
// AppsFlyerCocos2dX-mobile
//
// Created by AndreyG-AF on 10/17/17.
//
#import "AppsFlyerX+AppController.h"
#import <objc/runtime.h>
#import "AppsFlyer/libAppsFlyer/AppsFlyerLib.h"
@implementation AppController (AppsFlyerX)
static BOOL isOriginalImpementationExist;
+ (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Class class = [self class];
SEL originalSelector = @selector(application: continueUserActivity: restorationHandler:);
SEL swizzledSelector = @selector(x_application: continueUserActivity: restorationHandler:);
Method originalMethod = class_getInstanceMethod(class, originalSelector);
Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
isOriginalImpementationExist = [class instancesRespondToSelector:originalSelector];
BOOL didAddMethod =
class_addMethod(class,
originalSelector,
method_getImplementation(swizzledMethod),
method_getTypeEncoding(swizzledMethod));
if (didAddMethod) {
class_replaceMethod(class,
swizzledSelector,
method_getImplementation(originalMethod),
method_getTypeEncoding(originalMethod));
} else {
method_exchangeImplementations(originalMethod, swizzledMethod);
}
});
}
#pragma mark - Method Swizzling
- (BOOL)x_application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler {
[[AppsFlyerLib shared] continueUserActivity:userActivity restorationHandler:restorationHandler];
if (isOriginalImpementationExist) {
[self x_application:application continueUserActivity:userActivity restorationHandler:restorationHandler];
}
return YES;
}
@end