包含系统画中画 -- 如果不使用系统小窗 则不需要下面配置
1 整合準備
請先下載專案 Demo,並準備好保利威直播的觀看端連結,以體驗更完整的功能。
2 專案設定
2.1 設定支援系統版本
開啟專案的 PROJECT - Deployment Target - iOS Deployment Target,改為 9.0 或更高版本。
開啟專案的 TARGETS - General - Deployment Info,將 iOS 系統改為 9.0 或更高版本。
2.2 設定 App Transport Security (ATS)
開啟專案的 info.plist 檔案,加入以下內容:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSAllowsArbitraryLoadsInWebContent</key>
<true/>
</dict>
2.3 設定裝置旋轉
播放器支援全螢幕播放,需在 TARGETS - General - Deployment Info 中,勾選支援的橫向旋轉方向。
2.4 設定背景播放與子母畫面
開啟專案的 TARGETS - Signings & Capabilities,點選 + Capability,選擇 Background Modes,勾選 'Audio, AirPlay, and Picture in Picture'。
3 整合 SDK
3.1 使用 Pod 方式整合
3.1.1 整合 PLVWebViewSDK
在 Podfile 檔案中,加入以下內容:
pod 'PLVWebViewSDK', '~> 3.2.4'
在終端機執行 pod install
3.1.2 整合系統小視窗
若需要使用系統小視窗功能,則需在 Podfile 檔案中另外加入以下內容:
# 包含系统画中画 -- 如果不使用系统小窗 则不需要下面配置
pod 'PLVLiveScenesWebViewPIPModule', '1.10.6.3'
並在終端機執行 pod install。
3.2 使用離線包方式整合
3.2.1 整合 PLVWebViewSDK
將 PLVWebViewSDK.framework 函式庫加入自己的專案中。若使用原始碼方式整合,則需將 PLVWebViewSDK 檔案整個加入自己的專案即可。
3.2.2 整合系統小視窗
- 若專案使用系統小視窗功能,則需將以下函式庫加入專案中:
PLVAliHttpDNS、PLVBusinessSDK、PLVFoundationSDK、PLVIJKPlayer、PLVLiveScenesSDK
在 General => Frameworks, Libraries, and Embedded Content 中移除已加入的 PLVFoundationSDK.framework、PLVLiveScenesSDK.framework、PLVBusinessSDK.framework 函式庫,並加入系統函式庫 libresolv.tbd。
將 PLVIJKPlayer 設定為 Embed & Sign
在 Build Settings 的 Other Linker Flags 中加入 -ObjC,若專案已設定則無需重複加入。
執行錯誤
若模擬器執行錯誤,需在 Build Settings 中設定 Excluded Architecture => Any iOS Simulator SDK 為 arm64。
若執行錯誤:
Building for iOS Simulator, but the linked and embedded framework '***' was built for iOS + tvOS Simulator
可在 Build Settings 中設定 VALIDATE_WORKSPACE 為 YES 即可。
4 程式碼呼叫
建立欲顯示 WebView 的控制器頁面 DemoViewController,繼承自 PLVWebViewBaseViewController,並透過初始化方法 -initWithConfig: 建立控制器頁面。範例程式碼如下:
// PLVWebViewDemoViewController.h
#import <PLVWebViewSDK/PLVWebViewSDK.h>
@interface PLVWebViewDemoViewController : PLVWebViewBaseViewController
@end
初始化時可透過覆寫 initHandleForDemo 進行自訂設定,同時可對 Bridge 事件進行自訂處理。範例程式碼如下:
// PLVWebViewDemoViewController.m
@implementation PLVWebViewDemoViewController
#pragma mark - [ Override ]
- (void)viewDidLoad {
[super viewDidLoad];
}
/// 初始化时,可以进行的自定义配置
//- (void)initHandleForDemo {
//
//}
#pragma mark - [ Delegate ]
#pragma mark PLVFloatableWebViewBridgeDelegate
/// 如需要监听 js 回调事件,可以通过Delegate事件进行相应的处理,例如webviewBridgeShare消息
//- (void)webviewBridgeShare:(PLVFloatableWebViewBridge *)bridge {
//
//}
@end
建立、設定、開啟直播頁面控制器:
PLVWebViewConfig *config = [[PLVWebViewConfig alloc] init];
config.urlString = urlString;
config.allowFloatingWindow = YES;
config.isSystemFloatingWindow = NO;
config.userAgent = self.uaTextView.text;
config.enableAutoFloatWindow = YES;
PLVWebViewDemoViewController *webVC = [[PLVWebViewDemoViewController alloc] initWithConfig:config];
[self.navigationController pushViewController:webVC animated:YES];
