...
|
...
|
@@ -14,6 +14,44 @@ |
|
|
#import "YH_EventCollector.h"
|
|
|
#import "YHEventReport.h"
|
|
|
|
|
|
@interface UIViewController (AutoTrackPrivate)
|
|
|
|
|
|
@property (nonatomic, assign, readonly) BOOL shouldTrack;
|
|
|
@property (nonatomic, assign) BOOL shouldResetStartLoadDate;
|
|
|
|
|
|
@end
|
|
|
|
|
|
@implementation UIViewController (AutoTrackPrivate)
|
|
|
|
|
|
- (BOOL)shouldTrack {
|
|
|
return ![self isSystemContainerController] &&
|
|
|
![self shouldNotTrackByProtocol] &&
|
|
|
[YHEventReport sharedInstance].isPerformanceTrackEnabled &&
|
|
|
[YHEventReport sharedInstance].isControllerPerformanceTrackEnable &&
|
|
|
![[YHEventReport sharedInstance] isPerformanceViewControllerStringIgnored:NSStringFromClass([self class])];
|
|
|
}
|
|
|
|
|
|
- (BOOL)shouldNotTrackByProtocol {
|
|
|
return [self conformsToProtocol:@protocol(UIViewControllerPerformanceTrack)] &&
|
|
|
[(id<UIViewControllerPerformanceTrack>)self shouldNotTrackFirstPageLoadPerformance];
|
|
|
}
|
|
|
|
|
|
- (void)setShouldResetStartLoadDate:(BOOL)shouldResetStartLoadDate {
|
|
|
objc_setAssociatedObject(self, @selector(shouldResetStartLoadDate), @(shouldResetStartLoadDate), OBJC_ASSOCIATION_COPY_NONATOMIC);
|
|
|
}
|
|
|
|
|
|
- (BOOL)shouldResetStartLoadDate {
|
|
|
return [objc_getAssociatedObject(self, _cmd) boolValue];
|
|
|
}
|
|
|
|
|
|
- (BOOL)isSystemContainerController {
|
|
|
return [self isKindOfClass:[UINavigationController class]] ||
|
|
|
[self isKindOfClass:[UITabBarController class]] ||
|
|
|
[self isKindOfClass:[UISplitViewController class]] ||
|
|
|
[self isKindOfClass:[UIPageViewController class]];
|
|
|
}
|
|
|
|
|
|
@end
|
|
|
|
|
|
@implementation UIViewController (AutoTrack)
|
|
|
|
...
|
...
|
@@ -39,6 +77,15 @@ |
|
|
viewdidappearError = NULL;
|
|
|
}
|
|
|
|
|
|
NSError *viewwillappearError = NULL;
|
|
|
[[self class] yh_swizzleMethod:@selector(viewWillAppear:)
|
|
|
withMethod:@selector(yher_viewWillAppear:)
|
|
|
error:&viewwillappearError];
|
|
|
if (viewwillappearError) {
|
|
|
YHLog(@"Failed to swizzle viewWillAppear: on UIViewController. Details: %@", viewwillappearError);
|
|
|
viewdidappearError = NULL;
|
|
|
}
|
|
|
|
|
|
} @catch (NSException *exception) {
|
|
|
YHLog(@"%@ error: %@", self, exception);
|
|
|
}
|
...
|
...
|
@@ -48,19 +95,30 @@ |
|
|
|
|
|
- (void)yher_viewDidLoad{
|
|
|
@try {
|
|
|
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].isControllerPerformanceTrackEnable && ![[YHEventReport sharedInstance] isPerformanceViewControllerStringIgnored:NSStringFromClass([self class])]) {
|
|
|
if (self.shouldTrack) {
|
|
|
[[YH_EventCollector sharedInstance] timeEventStartWithViewController:self];
|
|
|
[self performSelector:@selector(yher_checkVisiable) withObject:nil afterDelay:0];
|
|
|
}
|
|
|
} @catch (NSException *exception) {
|
|
|
YHLog(@"%@ error: %@", self, exception);
|
|
|
}
|
|
|
|
|
|
[self yher_viewDidLoad];
|
|
|
}
|
|
|
|
|
|
-(void)yher_viewWillAppear:(BOOL)animated {
|
|
|
@try {
|
|
|
if (self.shouldTrack && self.shouldResetStartLoadDate && !self.yher_hasReported) {
|
|
|
[[YH_EventCollector sharedInstance] timeEventStartWithViewController:self];
|
|
|
}
|
|
|
} @catch (NSException *exception) {
|
|
|
YHLog(@"%@ error: %@", self, exception);
|
|
|
}
|
|
|
[self yher_viewWillAppear:animated];
|
|
|
}
|
|
|
|
|
|
-(void)yher_viewDidAppear:(BOOL)animated {
|
|
|
@try {
|
|
|
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].isControllerPerformanceTrackEnable && ![[YHEventReport sharedInstance] isPerformanceViewControllerStringIgnored:NSStringFromClass([self class])]) {
|
|
|
if (self.shouldTrack && !self.yher_hasReported) {
|
|
|
[[YH_EventCollector sharedInstance] timeEventEndWithViewController:self];
|
|
|
}
|
|
|
if ([YHEventReport sharedInstance].isAppCrashReportEnable && [YHEventReport sharedInstance].isAutoTrackEnabled) {
|
...
|
...
|
@@ -86,12 +144,18 @@ |
|
|
[self yher_viewDidAppear:animated];
|
|
|
}
|
|
|
|
|
|
- (void)yher_checkVisiable {
|
|
|
if (!self.view.window) {
|
|
|
self.shouldResetStartLoadDate = YES;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- (void)setYh_viewId:(NSString *)yh_viewId{
|
|
|
objc_setAssociatedObject(self,@selector(yh_viewId),yh_viewId,OBJC_ASSOCIATION_RETAIN);
|
|
|
}
|
|
|
|
|
|
- (NSString *)yh_viewId{
|
|
|
return objc_getAssociatedObject(self, @selector(yh_viewId));
|
|
|
return objc_getAssociatedObject(self, _cmd);
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
@@ -100,15 +164,15 @@ |
|
|
}
|
|
|
|
|
|
- (NSString *)yh_Alias{
|
|
|
return objc_getAssociatedObject(self, @selector(yh_Alias));
|
|
|
return objc_getAssociatedObject(self, _cmd);
|
|
|
}
|
|
|
|
|
|
- (void)setYher_hasReported:(NSString *)yher_hasReported{
|
|
|
objc_setAssociatedObject(self,@selector(yher_hasReported),yher_hasReported,OBJC_ASSOCIATION_RETAIN);
|
|
|
- (void)setYher_hasReported:(BOOL)yher_hasReported{
|
|
|
objc_setAssociatedObject(self,@selector(yher_hasReported),@(yher_hasReported),OBJC_ASSOCIATION_COPY_NONATOMIC);
|
|
|
}
|
|
|
|
|
|
- (NSString *)yher_hasReported{
|
|
|
return objc_getAssociatedObject(self, @selector(yher_hasReported));
|
|
|
- (BOOL)yher_hasReported{
|
|
|
return [objc_getAssociatedObject(self, _cmd) boolValue];
|
|
|
}
|
|
|
|
|
|
- (UITabBarController *)yher_tabBarController
|
...
|
...
|
|