Authored by 孙凯

add UITapGestureRecognizer review by hongmo

... ... @@ -46,9 +46,9 @@
B1475E671F7F37FC0066B514 /* NSURLConnection+AutoTrack.m in Sources */ = {isa = PBXBuildFile; fileRef = B1475E661F7F37FC0066B514 /* NSURLConnection+AutoTrack.m */; };
B1475E6D1F7F38280066B514 /* NSURLSession+AutoTrack.m in Sources */ = {isa = PBXBuildFile; fileRef = B1475E6C1F7F38280066B514 /* NSURLSession+AutoTrack.m */; };
B14C0C821F8DF22200D963F3 /* SDWebImageManager+AutoTrack.m in Sources */ = {isa = PBXBuildFile; fileRef = B14C0C811F8DF22200D963F3 /* SDWebImageManager+AutoTrack.m */; };
B14C0C991F8E2E9B00D963F3 /* UITapGestureRecognizer+AutoTrack.m in Sources */ = {isa = PBXBuildFile; fileRef = B14C0C981F8E2E9B00D963F3 /* UITapGestureRecognizer+AutoTrack.m */; };
B17F61DB1F6678CD009D1606 /* UserNotifications.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B17F61DA1F6678CD009D1606 /* UserNotifications.framework */; };
B1A393141F7B4E04009700D9 /* UIControl+AutoTrack.m in Sources */ = {isa = PBXBuildFile; fileRef = B1A393131F7B4E04009700D9 /* UIControl+AutoTrack.m */; };
B1A393171F7C918C009700D9 /* UIGestureRecognizer+AutoTrack.m in Sources */ = {isa = PBXBuildFile; fileRef = B1A393161F7C918C009700D9 /* UIGestureRecognizer+AutoTrack.m */; };
B1A9387C1F6A8AF600D6582C /* NSString+ER_URL.m in Sources */ = {isa = PBXBuildFile; fileRef = B1A9387B1F6A8AF600D6582C /* NSString+ER_URL.m */; };
B1B6C3A01F74AD3100627DF3 /* README.md in Sources */ = {isa = PBXBuildFile; fileRef = B1B6C3951F74AD3100627DF3 /* README.md */; };
B1B6C3A11F74AD3100627DF3 /* UIScrollView+YHExposure.m in Sources */ = {isa = PBXBuildFile; fileRef = B1B6C3991F74AD3100627DF3 /* UIScrollView+YHExposure.m */; };
... ... @@ -167,11 +167,11 @@
B1475E6C1F7F38280066B514 /* NSURLSession+AutoTrack.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSURLSession+AutoTrack.m"; sourceTree = "<group>"; };
B14C0C801F8DF22200D963F3 /* SDWebImageManager+AutoTrack.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "SDWebImageManager+AutoTrack.h"; sourceTree = "<group>"; };
B14C0C811F8DF22200D963F3 /* SDWebImageManager+AutoTrack.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "SDWebImageManager+AutoTrack.m"; sourceTree = "<group>"; };
B14C0C971F8E2E9B00D963F3 /* UITapGestureRecognizer+AutoTrack.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UITapGestureRecognizer+AutoTrack.h"; sourceTree = "<group>"; };
B14C0C981F8E2E9B00D963F3 /* UITapGestureRecognizer+AutoTrack.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UITapGestureRecognizer+AutoTrack.m"; sourceTree = "<group>"; };
B17F61DA1F6678CD009D1606 /* UserNotifications.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UserNotifications.framework; path = System/Library/Frameworks/UserNotifications.framework; sourceTree = SDKROOT; };
B1A393121F7B4E04009700D9 /* UIControl+AutoTrack.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIControl+AutoTrack.h"; sourceTree = "<group>"; };
B1A393131F7B4E04009700D9 /* UIControl+AutoTrack.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIControl+AutoTrack.m"; sourceTree = "<group>"; };
B1A393151F7C918C009700D9 /* UIGestureRecognizer+AutoTrack.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIGestureRecognizer+AutoTrack.h"; sourceTree = "<group>"; };
B1A393161F7C918C009700D9 /* UIGestureRecognizer+AutoTrack.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIGestureRecognizer+AutoTrack.m"; sourceTree = "<group>"; };
B1A9387A1F6A8AF600D6582C /* NSString+ER_URL.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSString+ER_URL.h"; sourceTree = "<group>"; };
B1A9387B1F6A8AF600D6582C /* NSString+ER_URL.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSString+ER_URL.m"; sourceTree = "<group>"; };
B1B6C3951F74AD3100627DF3 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
... ... @@ -315,14 +315,14 @@
29CDB4B01F6FA5A500AAD350 /* PowerfulBannerView+AutoTrack.m */,
B1A393121F7B4E04009700D9 /* UIControl+AutoTrack.h */,
B1A393131F7B4E04009700D9 /* UIControl+AutoTrack.m */,
B1A393151F7C918C009700D9 /* UIGestureRecognizer+AutoTrack.h */,
B1A393161F7C918C009700D9 /* UIGestureRecognizer+AutoTrack.m */,
B1475E651F7F37FC0066B514 /* NSURLConnection+AutoTrack.h */,
B1475E661F7F37FC0066B514 /* NSURLConnection+AutoTrack.m */,
B1475E6B1F7F38280066B514 /* NSURLSession+AutoTrack.h */,
B1475E6C1F7F38280066B514 /* NSURLSession+AutoTrack.m */,
B14C0C801F8DF22200D963F3 /* SDWebImageManager+AutoTrack.h */,
B14C0C811F8DF22200D963F3 /* SDWebImageManager+AutoTrack.m */,
B14C0C971F8E2E9B00D963F3 /* UITapGestureRecognizer+AutoTrack.h */,
B14C0C981F8E2E9B00D963F3 /* UITapGestureRecognizer+AutoTrack.m */,
);
path = YH_AOP;
sourceTree = "<group>";
... ... @@ -705,6 +705,7 @@
5255C2BB1F5D25F400A8FC5F /* YHSwizzle.m in Sources */,
52D204EE1F61360200CB7F1A /* UIActionSheet+AutoTrack.m in Sources */,
B1D774AE1F62A37E00BA89C3 /* UIImageView+HighlightedWebCache.m in Sources */,
B14C0C991F8E2E9B00D963F3 /* UITapGestureRecognizer+AutoTrack.m in Sources */,
B1D774A91F62A37E00BA89C3 /* SDWebImagePrefetcher.m in Sources */,
29D3B9791F739D8300B07F47 /* YH_EventCollector+PowerfulBannerView.m in Sources */,
B1D774A71F62A37E00BA89C3 /* SDWebImageDownloaderOperation.m in Sources */,
... ... @@ -735,7 +736,6 @@
5255C2C11F5D25F400A8FC5F /* YHEventReport.m in Sources */,
529A004B1F564E8500A83F63 /* main.m in Sources */,
B1C419021F616187005E0729 /* OpenUDID.m in Sources */,
B1A393171F7C918C009700D9 /* UIGestureRecognizer+AutoTrack.m in Sources */,
B1D774A51F62A37E00BA89C3 /* SDWebImageDownloader.m in Sources */,
52878C0D1F5FEE4C000A1597 /* YH_EventDataFactory.m in Sources */,
B1D774AC1F62A37E00BA89C3 /* UIImage+MultiFormat.m in Sources */,
... ...
... ... @@ -20,7 +20,7 @@
#import "UIViewController+AutoTrack.h"
#import "UITabBar+AutoTrack.h"
#import "UIControl+AutoTrack.h"
#import "UIGestureRecognizer+AutoTrack.h"
#import "UITapGestureRecognizer+AutoTrack.h"
#import "NSURLConnection+AutoTrack.h"
#define kYHEventReportIgnoredViewController @"YHEventReportQueue"
... ... @@ -149,7 +149,7 @@ static NSArray *kYHEventReportIgnoredViewControllerArray;
[UIViewController startTrack];
[UITabBar startTrack];
[UIControl startTrack];
[UIGestureRecognizer startTrack];
[UITapGestureRecognizer startTrack];
[NSURLConnection startTrack];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
... ...
//
// UIGestureRecognizer+AutoTrack.h
// UITapGestureRecognizer+AutoTrack.h
// YHEventReport
//
// Created by 孙凯 on 2017/9/28.
// Created by 孙凯 on 2017/10/11.
// Copyright © 2017年 YOHO. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIGestureRecognizer (AutoTrack)
@interface UITapGestureRecognizer (AutoTrack)
@property(nonatomic,copy)NSString *yh_viewId;//唯一ID
... ...
//
// UIGestureRecognizer+AutoTrack.m
// UITapGestureRecognizer+AutoTrack.m
// YHEventReport
//
// Created by 孙凯 on 2017/9/28.
// Created by 孙凯 on 2017/10/11.
// Copyright © 2017年 YOHO. All rights reserved.
//
#import "UIGestureRecognizer+AutoTrack.h"
#import "UITapGestureRecognizer+AutoTrack.h"
#import "YHSwizzle.h"
#import <objc/runtime.h>
#import <objc/message.h>
... ... @@ -14,13 +14,7 @@
#import "YHEventReport.h"
#import "YH_EventCollector.h"
@interface UIGestureRecognizer ()<UIGestureRecognizerDelegate>
@property(nullable,nonatomic,weak) id <UIGestureRecognizerDelegate> my_delegate;
@end
@implementation UIGestureRecognizer (AutoTrack)
@implementation UITapGestureRecognizer (AutoTrack)
#pragma mark - 属性
- (void)setYh_viewId:(NSString *)yh_viewId{
... ... @@ -31,16 +25,6 @@
return objc_getAssociatedObject(self, @selector(yh_viewId));
}
- (id)my_delegate
{
return objc_getAssociatedObject(self, _cmd);
}
- (void)setMy_delegate:(id)my_delegate
{
objc_setAssociatedObject(self, @selector(my_delegate), my_delegate, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
#pragma mark - load
+ (void)startTrack{
static dispatch_once_t onceToken;
... ... @@ -49,7 +33,6 @@
SEL selectors[] = {
@selector(initWithTarget:action:),
@selector(addTarget:action:),
@selector(setDelegate:),
};
for (NSUInteger index = 0; index < sizeof(selectors) / sizeof(SEL); ++index) {
... ... @@ -71,23 +54,10 @@
}
#pragma mark - hook API
-(void)yher_setDelegate:(id<UIGestureRecognizerDelegate>)delegate
{
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].buttonPerformanceTrackEnable && ([delegate isKindOfClass:[UIViewController class]] || [delegate isKindOfClass:[UIImageView class]] || [delegate isKindOfClass:[UILabel class]])) {
if (![delegate isKindOfClass:[self class]]) {
[self setMy_delegate:delegate];
return;
}
}
[self yher_setDelegate:delegate];
}
- (instancetype)yher_initWithTarget:(nullable id)target action:(nullable SEL)action
{
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].buttonPerformanceTrackEnable && ([target isKindOfClass:[UIViewController class]] || [target isKindOfClass:[UIImageView class]] || [target isKindOfClass:[UILabel class]])) {
[UIGestureRecognizer yher_exchangeSelector:action target:target toSelector:@selector(yher_gestureRecognizerDidTouch_cmd:)];
[self setDelegate:self];
if (([target isKindOfClass:[UIViewController class]] || [target isKindOfClass:[UIImageView class]] || [target isKindOfClass:[UILabel class]])) {
[UITapGestureRecognizer yher_exchangeSelector:action target:target toSelector:@selector(yher_gestureRecognizerDidTouch_cmd:)];
}
return [self yher_initWithTarget:target action:action];
}
... ... @@ -95,22 +65,26 @@
- (void)yher_addTarget:(id)target action:(SEL)action
{
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].buttonPerformanceTrackEnable && ([target isKindOfClass:[UIViewController class]] || [target isKindOfClass:[UIImageView class]] || [target isKindOfClass:[UILabel class]])) {
[UIGestureRecognizer yher_exchangeSelector:action target:target toSelector:@selector(yher_gestureRecognizerDidTouch_cmd:)];
[self setDelegate:self];
[UITapGestureRecognizer yher_exchangeSelector:action target:target toSelector:@selector(yher_gestureRecognizerDidTouch_cmd:)];
}
[self yher_addTarget:target action:action];
}
#pragma mark - action
- (void)yher_gestureRecognizerDidTouch_cmd:(UIGestureRecognizer*)sender
{
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].buttonPerformanceTrackEnable && ([sender.view isKindOfClass:[UIImageView class]] || [sender.view isKindOfClass:[UILabel class]])) {
[[YH_EventCollector sharedInstance] timeEventEndWithUIGestureRecognizer:sender];
if (([sender.view isKindOfClass:[UIImageView class]] || [sender.view isKindOfClass:[UILabel class]])) {
[[YH_EventCollector sharedInstance] timeEventStartWithUIGestureRecognizer:sender];
}
[self yher_gestureRecognizerDidTouch_cmd:sender];
if (([sender.view isKindOfClass:[UIImageView class]] || [sender.view isKindOfClass:[UILabel class]])) {
[[YH_EventCollector sharedInstance] timeEventEndWithUIGestureRecognizer:sender];
}
}
#pragma mark - hook func
... ... @@ -132,60 +106,4 @@
class_replaceMethod(originalClass,originalSelector,swizzledIMP,swizzledType);
}
#pragma mark - UIGestureRecognizerDelegate
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].buttonPerformanceTrackEnable) {
[[YH_EventCollector sharedInstance] timeEventStartWithUIGestureRecognizer:self];
}
if (self.my_delegate && [self.my_delegate respondsToSelector:@selector(gestureRecognizerShouldBegin:)]) {
return [self.my_delegate gestureRecognizerShouldBegin:gestureRecognizer];
}
return YES;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
if (self.my_delegate && [self.my_delegate respondsToSelector:@selector(gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:)]) {
return [self.my_delegate gestureRecognizer:gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:otherGestureRecognizer];
}
return YES;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRequireFailureOfGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
if (self.my_delegate && [self.my_delegate respondsToSelector:@selector(gestureRecognizer:shouldRequireFailureOfGestureRecognizer:)]) {
return [self.my_delegate gestureRecognizer:gestureRecognizer shouldRequireFailureOfGestureRecognizer:otherGestureRecognizer];
}
return YES;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
if (self.my_delegate && [self.my_delegate respondsToSelector:@selector(gestureRecognizer:shouldBeRequiredToFailByGestureRecognizer:)]) {
return [self.my_delegate gestureRecognizer:gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:otherGestureRecognizer];
}
return YES;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if (self.my_delegate && [self.my_delegate respondsToSelector:@selector(gestureRecognizer:shouldReceiveTouch:)]) {
return [self.my_delegate gestureRecognizer:gestureRecognizer shouldReceiveTouch:touch];
}
return YES;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceivePress:(UIPress *)press
{
if (self.my_delegate && [self.my_delegate respondsToSelector:@selector(gestureRecognizer:shouldReceivePress:)]) {
return [self.my_delegate gestureRecognizer:gestureRecognizer shouldReceivePress:press];
}
return YES;
}
@end
... ...
... ... @@ -18,7 +18,7 @@
#import "UIWebView+AutoTrack.h"
#import "UITabBarItem+Yoho.h"
#import "UIControl+AutoTrack.h"
#import "UIGestureRecognizer+AutoTrack.h"
#import "UITapGestureRecognizer+AutoTrack.h"
#define kYHEventReportQueue @"YHEventReportQueue"
#define kYHEventReporrH5StartKey @"YHEventReporrH5StartKey"
... ... @@ -349,8 +349,8 @@
}
#pragma mark - UIGestureRecognizer performance
- (void)timeEventStartWithUIGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
#pragma mark - UITapGestureRecognizer performance
- (void)timeEventStartWithUIGestureRecognizer:(UITapGestureRecognizer *)gestureRecognizer
{
NSNumber *startTime = @([[NSDate date] timeIntervalSince1970]);
NSString *viewId = [NSString stringWithFormat:@"%@%@",NSStringFromClass([gestureRecognizer class]),startTime];
... ... @@ -370,7 +370,7 @@
});
}
- (void)timeEventEndWithUIGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
- (void)timeEventEndWithUIGestureRecognizer:(UITapGestureRecognizer *)gestureRecognizer
{
NSTimeInterval elapsedTime = [self eventElapsedTime:gestureRecognizer.yh_viewId];
... ... @@ -386,7 +386,7 @@
NSDictionary *param = [YH_EventDataFactory factoryTimeEventDataWithUIGestureRecognizer:gestureRecognizer ElapsedTime:elapsedTime];
//NSLog(@"%@",param);
NSLog(@"%@",param);
if (param) {
[[YH_EventCacheManager sharedInstance] pushPerformanceData:param pointName:YHPN_GESTURERECOGNIZER];
}
... ...
... ... @@ -91,7 +91,7 @@ typedef NS_ENUM(NSInteger, YHEventReportPointName) {
YHPN_WEBVIEW,//UIWebView 加载时间 // @"WEBVIEW"
YHPN_IMAGEVIEW,//Image (SDWebImage) 加载时间 // @"IMAGE"
YHPN_BUTTON,//Button 响应时间 // @"BUTTON"
YHPN_GESTURERECOGNIZER //UIGestureRecognizer响应时间// @"GESTURERECOGNIZER"
YHPN_GESTURERECOGNIZER //UITapGestureRecognizer响应时间// @"GESTURERECOGNIZER"
};
typedef NS_ENUM(NSInteger, YHEventReportType) {
... ...
... ... @@ -21,7 +21,7 @@
+(NSDictionary *)factoryTimeEventDataWithUIControl:(UIControl *)control ElapsedTime:(NSTimeInterval)elapsedTime;
+(NSDictionary *)factoryTimeEventDataWithUIGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer ElapsedTime:(NSTimeInterval)elapsedTime;
+(NSDictionary *)factoryTimeEventDataWithUIGestureRecognizer:(UITapGestureRecognizer *)gestureRecognizer ElapsedTime:(NSTimeInterval)elapsedTime;
+ (NSDictionary *)factoryEventAppInfo:(YH_PerformanceAppInfo*)appInfo;
... ...
... ... @@ -66,7 +66,7 @@
return dict;
}
+(NSDictionary *)factoryTimeEventDataWithUIGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer ElapsedTime:(NSTimeInterval)elapsedTime {
+(NSDictionary *)factoryTimeEventDataWithUIGestureRecognizer:(UITapGestureRecognizer *)gestureRecognizer ElapsedTime:(NSTimeInterval)elapsedTime {
NSString *className = NSStringFromClass([gestureRecognizer class]);
... ...