Commit 3e8b90a6 authored by 汪洋's avatar 汪洋

refereredId自动获取

parent 3ef8a9dd
...@@ -281,6 +281,7 @@ static NSString *sdkVersion = @"110"; ...@@ -281,6 +281,7 @@ static NSString *sdkVersion = @"110";
- (void)onPVStart:(UIResponder<PhobosPVProtocol> *)page { - (void)onPVStart:(UIResponder<PhobosPVProtocol> *)page {
// 必须在此处调用一下referer,因为onControllerStart // 必须在此处调用一下referer,因为onControllerStart
[page initReferer]; [page initReferer];
[page initReferrerIdIfNil ];
page.inTime = [PhobosUtil currentTime]; page.inTime = [PhobosUtil currentTime];
} }
......
...@@ -14,4 +14,9 @@ ...@@ -14,4 +14,9 @@
只适用于controller自动初始化referer 只适用于controller自动初始化referer
*/ */
- (void)initReferer; - (void)initReferer;
/**
此方法在onPvStart时调用,如果发现已经有值了,不会给referrerId再次赋值
*/
- (void)initReferrerIdIfNil;
@end @end
...@@ -72,26 +72,26 @@ ...@@ -72,26 +72,26 @@
return inTime; return inTime;
} }
- (void)initReferrerIdIfNil {
if (self.referrerId == nil && [self isKindOfClass:[UIViewController class]]) {
NSArray *navigationPool = ((UIViewController *)self).navigationController.viewControllers;
NSInteger refererIdIndex = navigationPool.count - 2;
if (refererIdIndex < 0) {
objc_setAssociatedObject(self, @selector(referrerId), @"", OBJC_ASSOCIATION_COPY);
} else {
UIViewController *controller = navigationPool[refererIdIndex];
NSString *preBusinessId = controller.businessId;
objc_setAssociatedObject(self, @selector(referrerId), preBusinessId, OBJC_ASSOCIATION_COPY);
}
}
}
- (void)setReferrerId:(NSString *)referrerId { - (void)setReferrerId:(NSString *)referrerId {
objc_setAssociatedObject(self, @selector(referrerId), referrerId, OBJC_ASSOCIATION_COPY); objc_setAssociatedObject(self, @selector(referrerId), referrerId, OBJC_ASSOCIATION_COPY);
} }
- (NSString *)referrerId { - (NSString *)referrerId {
NSString *referrerId = objc_getAssociatedObject(self, @selector(referrerId)); NSString *referrerId = objc_getAssociatedObject(self, @selector(referrerId));
if (referrerId == nil) {
if ([self isKindOfClass:[UIViewController class]]) {
NSArray *navigationPool = ((UIViewController *)self).navigationController.viewControllers;
NSInteger refererIdIndex = navigationPool.count - 2;
if (refererIdIndex < 0) {
return @"";
} else {
UIViewController *controller = navigationPool[refererIdIndex];
NSString *preBusinessId = controller.businessId;
objc_setAssociatedObject(self, @selector(referrerId), preBusinessId, OBJC_ASSOCIATION_COPY);
return preBusinessId;
}
}
}
return referrerId; return referrerId;
} }
......
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