Commit 2c86f2d8 authored by 叶凤鸣's avatar 叶凤鸣

添加tab_name

parent 2c98ab14
...@@ -326,7 +326,7 @@ static NSString *sdkVersion = @"110"; ...@@ -326,7 +326,7 @@ static NSString *sdkVersion = @"110";
// 必须在此处调用一下referer,因为onControllerStart // 必须在此处调用一下referer,因为onControllerStart
[page initReferer]; [page initReferer];
[page initReferrerIdIfNil]; [page initReferrerIdIfNil];
[page initHomeTabName]; [page initReferrerTabName];
page.inTime = [PhobosUtil currentTime]; page.inTime = [PhobosUtil currentTime];
} }
...@@ -346,7 +346,7 @@ static NSString *sdkVersion = @"110"; ...@@ -346,7 +346,7 @@ static NSString *sdkVersion = @"110";
[dict setObject:page.referrerId ? : @"" forKey:@"referrer_id"]; [dict setObject:page.referrerId ? : @"" forKey:@"referrer_id"];
[dict setObject:page.extraParam ? : @"" forKey:@"extra_param"]; [dict setObject:page.extraParam ? : @"" forKey:@"extra_param"];
[dict setObject:page.homeTabName ? : @"" forKey:@"tab_name"]; [dict setObject:page.homeTabName ? : @"" forKey:@"tab_name"];
[dict setObject:page.currentTabName ? : @"" forKey:@"referrer_tab_name"]; [dict setObject:page.referrerTabName ? : @"" forKey:@"referrer_tab_name"];
NSAssert(page.inTime.length > 0, @"页面显示时间不能为空!"); NSAssert(page.inTime.length > 0, @"页面显示时间不能为空!");
[Phobos track:@"page_view" attributes:dict]; [Phobos track:@"page_view" attributes:dict];
if (page.inTime.length > 0) { if (page.inTime.length > 0) {
......
...@@ -61,11 +61,11 @@ ...@@ -61,11 +61,11 @@
/** /**
首页tab名称 首页tab名称
*/ */
@property (nonatomic, copy) NSString *homeTabName; @property (nonatomic, copy) NSString *tabName;
/** /**
获取上一个页面的tab名称 获取上一个页面的tab名称
*/ */
@property (nonatomic, copy) NSString *currentTabName; @property (nonatomic, copy) NSString *referrerTabName;
@end @end
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
- (void)initReferrerIdIfNil; - (void)initReferrerIdIfNil;
/** /**
此方法在onPvStart时调用,给currentTabName赋值 此方法在onPvStart时调用,给referrerTabName赋值
*/ */
- (void)initHomeTabName; - (void)initReferrerTabName;
@end @end
...@@ -46,11 +46,11 @@ ...@@ -46,11 +46,11 @@
} }
/** /**
此方法在onPvStart时调用,给currentTabName赋值,来源为首页时,才给currentTabName赋值,因为首页的pageName为home或者zone_v3,聚合页的pageName也是zone_v3,所以根据referer判断来源可能为首页或者聚合页,但是只有首页有tab名称,所以currentTabName为首页tab名称 此方法在onPvStart时调用,给referrerTabName赋值
*/ */
- (void)initHomeTabName { - (void)initReferrerTabName {
// 只有不为空,且是controller的情况下才自动获取 // 只有是controller的情况下才自动获取
if (([self.referer isEqualToString:@"home"] || [self.referer isEqualToString:@"zone_v3"]) && [self isKindOfClass:[UIViewController class]]) { if ([self isKindOfClass:[UIViewController class]]) {
// 分present与navigation两种情况 // 分present与navigation两种情况
UIViewController *me = (UIViewController *)self; UIViewController *me = (UIViewController *)self;
if (me.presentingViewController != nil) { if (me.presentingViewController != nil) {
...@@ -58,13 +58,9 @@ ...@@ -58,13 +58,9 @@
// 所以此处要判断,如果是navigation弹出,最后还是要定位到topViewController // 所以此处要判断,如果是navigation弹出,最后还是要定位到topViewController
if ([me.presentingViewController isKindOfClass:[UINavigationController class]]) { if ([me.presentingViewController isKindOfClass:[UINavigationController class]]) {
UIViewController *top = ((UINavigationController *)me.presentingViewController).topViewController; UIViewController *top = ((UINavigationController *)me.presentingViewController).topViewController;
if (![top.homeTabName isEqualToString:@""]) { objc_setAssociatedObject(self, @selector(referrerTabName), top.tabName, OBJC_ASSOCIATION_COPY);
objc_setAssociatedObject(self, @selector(currentTabName), top.homeTabName, OBJC_ASSOCIATION_COPY);
}
} else { } else {
if (![me.presentingViewController.homeTabName isEqualToString:@""]) { objc_setAssociatedObject(self, @selector(referrerTabName), me.presentingViewController.tabName, OBJC_ASSOCIATION_COPY);
objc_setAssociatedObject(self, @selector(currentTabName), me.presentingViewController.homeTabName, OBJC_ASSOCIATION_COPY);
}
} }
} else { } else {
NSArray *navigationPool = ((UIViewController *)self).navigationController.viewControllers; NSArray *navigationPool = ((UIViewController *)self).navigationController.viewControllers;
...@@ -73,9 +69,7 @@ ...@@ -73,9 +69,7 @@
return ; return ;
} }
UIViewController *controller = navigationPool[refererIndex]; UIViewController *controller = navigationPool[refererIndex];
if (![controller.homeTabName isEqualToString:@""]) { objc_setAssociatedObject(self, @selector(referrerTabName), controller.tabName, OBJC_ASSOCIATION_COPY);
objc_setAssociatedObject(self, @selector(currentTabName), controller.homeTabName, OBJC_ASSOCIATION_COPY);
}
} }
} }
} }
...@@ -169,22 +163,22 @@ ...@@ -169,22 +163,22 @@
return extraParam == nil ? @"" : extraParam; return extraParam == nil ? @"" : extraParam;
} }
- (void)setHomeTabName:(NSString *)homeTabName { - (void)setTabName:(NSString *)tabName {
objc_setAssociatedObject(self, @selector(homeTabName), homeTabName, OBJC_ASSOCIATION_COPY); objc_setAssociatedObject(self, @selector(tabName), tabName, OBJC_ASSOCIATION_COPY);
} }
- (NSString *)homeTabName { - (NSString *)tabName {
NSString *homeTabName = objc_getAssociatedObject(self, @selector(homeTabName)); NSString *tabName = objc_getAssociatedObject(self, @selector(tabName));
return homeTabName == nil ? @"" : homeTabName; return tabName == nil ? @"" : tabName;
} }
- (void)setCurrentTabName:(NSString *)currentTabName { - (void)setReferrerTabName:(NSString *)referrerTabName {
objc_setAssociatedObject(self, @selector(currentTabName), currentTabName, OBJC_ASSOCIATION_COPY); objc_setAssociatedObject(self, @selector(referrerTabName), referrerTabName, OBJC_ASSOCIATION_COPY);
} }
- (NSString *)currentTabName { - (NSString *)referrerTabName {
NSString *currentTabName = objc_getAssociatedObject(self, @selector(currentTabName)); NSString *referrerTabName = objc_getAssociatedObject(self, @selector(referrerTabName));
return currentTabName == nil ? @"" : currentTabName; return referrerTabName == nil ? @"" : referrerTabName;
} }
@end @end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment