@@ -22,16 +22,18 @@ @interface RUMView:NSObject
22
22
@property (nonatomic , copy ) NSString *identify;
23
23
@property (nonatomic , strong ) NSNumber *loadTime;
24
24
@property (nonatomic , weak ) UIViewController *viewController;
25
- -(instancetype )initWithViewController : (UIViewController *)viewController ;
25
+ @property (nonatomic , assign ) BOOL isUntrackedModal;
26
+ - (instancetype )initWithViewController : (UIViewController *)viewController identify : (NSString *)identify ;
26
27
- (void )updateViewControllerUUID ;
27
28
- (NSString *)viewControllerUUID ;
28
29
@end
29
30
@implementation RUMView
30
- -(instancetype )initWithViewController : (UIViewController *)viewController {
31
+ -(instancetype )initWithViewController : (UIViewController *)viewController identify : ( NSString *) identify {
31
32
self = [super init ];
32
33
if (self){
33
34
_viewName = viewController.ft_viewControllerName ;
34
- _identify = [NSString stringWithFormat: @" %p " , viewController];
35
+ _identify = identify;
36
+ _isUntrackedModal = NO ;
35
37
if (viewController.ft_viewUUID == nil ){
36
38
viewController.ft_viewUUID = [FTBaseInfoHandler randomUUID ];
37
39
}
@@ -149,29 +151,42 @@ -(void)applicationWillEnterForeground{
149
151
}
150
152
#pragma mark ========== FTUIViewControllerHandler ==========
151
153
-(void )notify_viewDidAppear : (UIViewController *)viewController animated : (BOOL )animated {
152
- if (![self shouldTrackViewController: viewController]){
154
+ NSString *identify = [NSString stringWithFormat: @" %p " , viewController];
155
+ __block RUMView *view = nil ;
156
+ [self .stack enumerateObjectsUsingBlock: ^(RUMView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
157
+ if ([obj.identify isEqualToString: identify]) {
158
+ *stop = YES ;
159
+ view = obj;
160
+ }
161
+ }];
162
+ if (view != nil ){
163
+ [self addView: view];
153
164
return ;
154
165
}
155
- RUMView *view = [[RUMView alloc ]initWithViewController:viewController];
156
- [self addView: view];
166
+ if ([self shouldTrackViewController: viewController]){
167
+ view = [[RUMView alloc ]initWithViewController:viewController identify: identify];
168
+ [self addView: view];
169
+ }else if (@available (iOS 13.0 ,tvOS 13.0 , *)){
170
+ if (viewController.isModalInPresentation ){
171
+ view = [[RUMView alloc ]initWithViewController:viewController identify: identify];
172
+ view.isUntrackedModal = YES ;
173
+ [self addView: view];
174
+ }
175
+ }
157
176
}
158
177
-(void )notify_viewDidDisappear : (UIViewController *)viewController animated : (BOOL )animated {
159
- if (![self shouldTrackViewController: viewController]){
160
- return ;
161
- }
162
- [self removeView: viewController viewControllerUUID: viewController.ft_viewUUID];
178
+ [self removeView: viewController];
163
179
}
164
180
- (void )addView : (RUMView *)view {
165
181
if ([[self .stack lastObject ].identify isEqualToString: view.identify]){
166
182
return ;
167
183
}
168
184
if ([self .stack lastObject ]) {
169
- // 没有从数组中移除的原因是有一些特殊视图,比如模态视图添加到window时 ,原有的 VC 并不会调用 didDisappear 方法,当这些特殊视图移除时,原有的 VC 也不会调用 DidAppear 方法,所以需要保留,重新添加到 RUM View。
185
+ // 没有从数组中移除的原因是有一些特殊视图,比如模态视图添加到 window 时,或者新的 window 添加到窗口,window 上有 VC ,原有的 VC 并不会调用 didDisappear 方法,当这些特殊视图移除时,原有的 VC 也不会调用 DidAppear 方法,所以需要保留,重新添加到 RUM View。
170
186
RUMView *current = [self .stack lastObject ];
171
- [self .addRumDatasDelegate stopViewWithViewID : current.identify property: nil ];
187
+ [self stopView : current];
172
188
}
173
- [self .addRumDatasDelegate onCreateView: view.viewName loadTime: view.loadTime];
174
- [self .addRumDatasDelegate startViewWithViewID: view.viewControllerUUID viewName: view.viewName property: nil ];
189
+ [self startView: view];
175
190
176
191
[self .stack enumerateObjectsWithOptions: NSEnumerationReverse usingBlock: ^(RUMView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
177
192
if ([obj.identify isEqualToString: view.identify]){
@@ -180,7 +195,7 @@ - (void)addView:(RUMView *)view{
180
195
}];
181
196
[self .stack addObject: view];
182
197
}
183
- - (void )removeView : (UIViewController *)viewController viewControllerUUID : ( NSString *) viewControllerUUID {
198
+ - (void )removeView : (UIViewController *)viewController {
184
199
NSString *identify = [NSString stringWithFormat: @" %p " , viewController];
185
200
if (![[self .stack lastObject ].identify isEqualToString: identify]){
186
201
[self .stack enumerateObjectsWithOptions: NSEnumerationReverse usingBlock: ^(RUMView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
@@ -190,28 +205,39 @@ - (void)removeView:(UIViewController *)viewController viewControllerUUID:(NSStri
190
205
}];
191
206
return ;
192
207
}
193
- [self .stack removeLastObject ];
194
- [self .addRumDatasDelegate stopViewWithViewID: viewControllerUUID property: nil ];
208
+ RUMView *stopView = [self .stack lastObject ];
209
+ if (stopView){
210
+ [self .stack removeLastObject ];
211
+ [self stopView: stopView];
212
+ }
195
213
196
- if ( [self .stack lastObject ]){
197
- RUMView *current = [ self .stack lastObject ];
198
- [current updateViewControllerUUID ];
199
- [self .addRumDatasDelegate startViewWithViewID: current.viewControllerUUID viewName: current.viewName property: nil ];
214
+ RUMView *reStartView = [self .stack lastObject ];
215
+ if (reStartView){
216
+ [reStartView updateViewControllerUUID ];
217
+ [self startView: reStartView ];
200
218
}
201
219
}
202
- - (BOOL ) shouldTrackViewController : (UIViewController *)viewController {
203
- if ([viewController isBlackListContainsViewController ] ){
204
- return NO ;
220
+ - (void ) startView : (RUMView *)view {
221
+ if (!self. addRumDatasDelegate ){
222
+ return ;
205
223
}
206
- UIViewController *parent = viewController.parentViewController ;
207
- while (parent != nil ) {
208
- if ([parent isKindOfClass: UIPageViewController.class] || [parent isKindOfClass: UISplitViewController.class]) {
209
- return NO ;
210
- }else {
211
- parent = parent.parentViewController ;
212
- }
224
+ // 确保黑名单视图,不会影响采集视图的 duration
225
+ // 黑名单视图模态弹出时,关闭上一个采集的 View,关闭时,重新开启上一个 View 采集
226
+ if (!view.isUntrackedModal ){
227
+ [self .addRumDatasDelegate onCreateView: view.viewName loadTime: view.loadTime];
228
+ [self .addRumDatasDelegate startViewWithViewID: view.viewControllerUUID viewName: view.viewName property: nil ];
229
+ }
230
+ }
231
+ - (void )stopView : (RUMView *)view {
232
+ if (!self.addRumDatasDelegate ){
233
+ return ;
234
+ }
235
+ if (!view.isUntrackedModal ){
236
+ [self .addRumDatasDelegate stopViewWithViewID: view.viewControllerUUID property: nil ];
213
237
}
214
- return YES ;
238
+ }
239
+ - (BOOL )shouldTrackViewController : (UIViewController *)viewController {
240
+ return ![viewController isBlackListContainsViewController ];
215
241
}
216
242
-(void )shutDown {
217
243
self.stack = nil ;
0 commit comments