admin
2022-09-04 fa05f89529e05078b29606e4beda3de5cfdce485
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//
//  CSJWebViewControllerViewModel.h
//  CSJAdSDK
//
//  Created by wangyanlin on 2020/8/26.
//  Copyright © 2020 bytedance. All rights reserved.
//
 
#import <Foundation/Foundation.h>
#import "CSJAdSlot.h"
#import <UIKit/UIKit.h>
#import "CSJWKWebViewClient.h"
 
@class CSJDislikeContext;
 
struct BUWebViewClickStruct {
    CGPoint point;
    NSString *tag;
};
 
typedef NS_ENUM(NSUInteger, BUWebViewHeartBeatState) {
    BUWebViewHeartBeatState_Stable, //正常稳定状态(暂不适用)
    BUWebViewHeartBeatState_Break, //断开
};
 
typedef NS_ENUM(NSUInteger, BULandingPageType) {
    BULandingPageType_None = 0, //非落地页类型
    BULandingPageType_Direct = 1, //全屏直出落地页场景
    BULandingPageType_Split = 2, //7分屏落地页
};
 
typedef void (^BUWebViewHeartBeatCallback)(BUWebViewHeartBeatState type);
 
 
@interface CSJWebViewControllerViewModel : NSObject <BUWebViewDelegate>
 
@property (nonatomic, strong) CSJWKWebViewClient *webView;
@property (nonatomic, readonly) id<CSJAd> adInfo;
@property (nonatomic, strong) CSJAdSlot *adSlot;
@property (nonatomic, copy) NSString *webTitle;
@property (nonatomic, assign, readonly) BOOL isNavBarHidden;
@property (nonatomic, assign) BOOL isHiddenProgress; //展示进度条,默认为NO
@property (nonatomic, copy) void(^CloseBlock)(void);
@property (nonatomic, strong) NSURL *requestURL;
@property (nonatomic, assign, getter=isSupportAlert) BOOL supportAlert; // 是否支持前端 alert 弹窗,默认为 YES
@property (nonatomic, assign) BOOL hasTerminateTrack;//是否已经上报过一次 webview 崩溃
@property (nonatomic, strong) NSDictionary *relatedMaterialMeta; // 相关推荐物料或者鲁班聚合页引流广告
@property (nonatomic, copy) NSString *createExtraString; // H5落地页自建站增加的字段
@property (nonatomic, copy) dispatch_block_t hasLoadLubanListPage;  // 加载鲁班聚合页
@property (nonatomic, assign) BULandingPageType landingPageType; // 海外链路优选七分屏落地页
@property (nonatomic, assign) BOOL isFromClick;
@property (nonatomic, assign) BUVideoWebPageType pageType;
 
/// 落地页适配iOS 14.5 商店关闭回调
@property (nonatomic, copy) dispatch_block_t downloadDidCloseStoreController;
/*
 @param isNavBarHidden业务方使用,可选是否隐藏navigationBar,例如encard、视频详情页下半部分可以设置成YES,落地页可以设置成NO
 @param size webview的size,需要前置确定,为了兼容playable使用wkwebview进行预加载,必须提前传入frame
 */
- (instancetype)initWithRequestURL:(NSURL *)requestURL adinfo:(id<CSJAd>)adinfo size:(CGSize)size isNavBarHidden:(BOOL)isNavBarHidden;
 
/*
 @param isNavBarHidden业务方使用,可选是否隐藏navigationBar,例如encard、视频详情页下半部分可以设置成YES,落地页可以设置成NO
 @param size webview的size,需要前置确定,为了兼容playable使用wkwebview进行预加载,必须提前传入frame
 @param isLandingpageSplitScreen 海外优选链路专用字段
 */
- (instancetype)initWithRequestURL:(NSURL *)requestURL adinfo:(id<CSJAd>)adinfo size:(CGSize)size isNavBarHidden:(BOOL)isNavBarHidden landingPageType:(BULandingPageType)landingPageType;
- (instancetype)initWithRequestURL:(NSURL *)requestURL adinfo:(id<CSJAd>)adinfo size:(CGSize)size isNavBarHidden:(BOOL)isNavBarHidden landingPageType:(BULandingPageType)landingPageType isFromClick:(BOOL)isFromClick;
 
- (void)bu_loadRequest:(NSURL *)requestURL;
 
 
/**************** subclass overwrite ****************/
- (void)sendTrackDataWithParameters:(NSDictionary *)dict;
- (void)goback:(id)sender;
- (void)goClose:(id)sender;
- (void)appDidEnterBackgroundNotification:(NSNotification *)notification;
- (void)appWillEnterForegroundNotification:(NSNotification *)notification;
- (void)handleError:(NSError *)error;
/// 是否使用拦截cache
- (BOOL)useCache;
///注册点击监听
- (void)registJS_Tap;
/// 获取埋点tag
- (NSString *)getTrackTag;
///监听h5心跳, 同一个实例只有一份监听
- (void)observeHeartBeatWithOverTime:(NSInteger)overTime callback:(BUWebViewHeartBeatCallback)callback;
///取消监听h5心跳
- (void)cancelObserveHeartBeat;
 
//- (void)removeAllScriptMsgHandleForName:(NSString *)name;
/**************** subclass overwrite ****************/
 
/**************** VM related ****************/
@property (nonatomic, weak) UIView *view;//containerView
 
@property (nonatomic, weak) UIViewController *parentVC;//optional 落地页点击 返回/关闭 pop vc 使用; 设置 VC 的 title 使用
 
// VC lift cycle
- (void)handleViewDidLoad;
 
- (void)handleViewWillLayoutSubviews;
 
- (void)handleViewWillAppear:(BOOL)animated;
 
- (void)handleViewDidAppear:(BOOL)animated;
 
- (void)handleViewWillDisappear:(BOOL)animated;
 
- (void)handleViewDidDisappear:(BOOL)animated;
 
- (void)handleDidReceiveMemoryWarning;
 
///web点击事件
- (void)handleTapWithInfo:(NSString *)info;
 
- (BOOL)isRealPlayablePage;
// 子类重写
- (BOOL)shouldTrack;
- (NSString *)trackTag;
- (BOOL)useLandingPageNewStyle;
 
- (void)responseViewClick:(struct BUWebViewClickStruct)click;
- (void)responseViewDidScroll:(struct BUWebViewClickStruct)click offset:(CGPoint)offset;
// 链路优选需求第一次点击webview上报埋点
- (void)responseViewFirstClick:(struct BUWebViewClickStruct)click;
- (BOOL)isOverseaLPNewStyle;
 
@end