SDK導入說明
須先行下載tvOS SDK檔案後,即進行解壓縮程序,包含了二個Framework檔,並完成以下三項前置步驟:
A.在本Mid Roll 廣告專案中
只需加入 iMFADTV Framework, GoogleInteractiveMediaAds Framework
B.在 Build Settings 內 Other Linker Flags 請填入 -all_load 與 -ObjC
C.App Transport Security Settings,需進行設定。
基本設定
引入SDK
iMFADTV Framework 、 GoogleInteractiveMediaAds Framework 加入方式
在TARGETS-開啟 General
分頁下的 Frameworks, Libraries, and Embedded Content
下拉式選單,
然後用畫面上出現的 +
按鈕加入。
修改Build Settings
在專案設定選項中的 Build Settings下的 Other Linker Flags 加入-ObjC
、 -all_load
修改info.plist
iOS9 App Transport Security Settings
NSAllowsArbitraryLoads
規則並設定為允許。請在 info.plist 中加入以下規則。1.加入步驟為 新增App Transport Security Settings
, 並在底下新增Allow Arbitrary Loads
,將其設為 YES
開始建立 Mid Roll 廣告
MFPreRollView 參數設定與說明
* 以下必須使用方法
設定 MFPreRollView
Parameters (此參數設定會自動幫您控制 暫停 及 播放)
請輸入Mid Roll VAST 板位ID
Parameters
設定Mid Roll 廣告載入
使用 MFPreRollDelegate
@property(nonatomic,weak)id<MFPreRollDelegate>delegate;
設定指向放置PreRoll廣告頁面
Parameters
* 以下為選擇使用方法
初始化時設定CGRect大小
- (id)initWithFrame:(CGRect) frame
Parameters
初始化時設定大小與UIView相同
-(id)initWithView:(UIView *) playerView
Parameters
關閉Mid-roll 影片
Usage
繼續播放Mid-roll 影片
Usage
取得/查看 版本&IMA版本
Usage
MFPreRollDelegate 說明
Mid-roll Vast影片播完處理
Mid-roll Vast影片錯誤處理
宣告及引入
請在需要引入廣告的地方加入#import <iMFAD/iMFAD.h> ,並加入MFPreRollDelegate
#import <UIKit/UIKit.h>
#import <iMFADTV/iMFADTV.h>
// 增加一個protocol接收Mid Roll播放狀態
@interface ViewController : UIViewController<MFPreRollDelegate>
{
MFPreRollView *preroll; // 宣告使用 Mid Roll廣告
}
@end
以下程式碼會在 viewController的 viewDidLoad 初始化步驟中建立Mid Roll VAST 影音廣告。
#import "ViewController.h" NSString *const kContentURLString = @"https://v.holmesmind.com/1151/video/output/s_f96434d0f311f12bdcf5145796985719.mp4"; @interface ViewController () @property(nonatomic) AVPlayerViewController *contentPlayerViewController; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self setupContentPlayer]; //示範五秒後進入廣告 [self performSelector:@selector(setMidRoll) withObject:nil afterDelay:5]; } - (void)setMidRoll{ NSLog(@"Set MidRoll"); [self hideContentPlayer]; midroll = [[MFPreRollView alloc] initWithMidRollFrame:self.contentPlayerViewController]; [midroll setZoneID:@"18379" getViewController:self]; midroll.delegate = self; [midroll setPlayer]; } - (void)readyPlayVideo{ NSLog(@"%s",__FUNCTION__); NSLog(@"Ad play done."); [self showContentPlayer]; } - (void)onFailedToVast{ NSLog(@"%s",__FUNCTION__); } - (void)setupContentPlayer { // Create a content video player. NSURL *contentURL = [NSURL URLWithString:kContentURLString]; AVPlayer *player = [AVPlayer playerWithURL:contentURL]; self.contentPlayerViewController = [[AVPlayerViewController alloc] init]; self.contentPlayerViewController.player = player; self.contentPlayerViewController.view.frame = self.view.bounds; // Attach content video player to view hierarchy. [self showContentPlayer]; } // Add the content video player as a child view controller. - (void)showContentPlayer { [self addChildViewController:self.contentPlayerViewController]; self.contentPlayerViewController.view.frame = self.view.bounds; [self.view insertSubview:self.contentPlayerViewController.view atIndex:0]; [self.contentPlayerViewController didMoveToParentViewController:self]; [self.contentPlayerViewController.player play]; } // Remove and detach the content video player. - (void)hideContentPlayer { // The whole controller needs to be detached so that it doesn't capture events from the remote. [self.contentPlayerViewController willMoveToParentViewController:nil]; [self.contentPlayerViewController.view removeFromSuperview]; [self.contentPlayerViewController removeFromParentViewController]; [self.contentPlayerViewController.player pause]; } @end
取得結果
show date