「SDK8 Interstitial」修訂間的差異

出自TAMedia
跳至導覽 跳至搜尋
imported>Wikiuser
 
(未顯示同一使用者於中間所作的 2 次修訂)
行 23: 行 23:


== InterstitialViewController.swift ==
== InterstitialViewController.swift ==
<source>
<nowiki>
import TAMediaAdsFramework
import TAMediaAdsFramework


行 55: 行 55:
     }
     }
}
}
</source>
</nowiki>
 


== TADInterstitialDelegate ==
== TADInterstitialDelegate ==
<source>
<nowiki>
extension InterstitialViewController: TADInterstitialDelegate {
extension InterstitialViewController: TADInterstitialDelegate {
     // 廣告取得成功,可以在此時間點及之後顯示呈現廣告
     // 廣告取得成功,可以在此時間點及之後顯示呈現廣告
行 88: 行 87:
     }
     }
}
}
</source>
</nowiki>





於 2022年4月21日 (四) 08:17 的最新修訂

回 SDK 8首頁

簡介

Interstitial 廣告可以在 app 啟動, 視頻載入期間或遊戲暫停的時候,呈現內容豐富的蓋版 HTML5 網頁。
以下將告訴您如何讓您的 app 顯示 Interstitial 廣告。

串接準備

開始串接前請間確定已將 TAmedia SDK 整合至專案,並且完成初始化 SDK步驟,若您尚未完成請先參考開始使用教學完成相關設定。

Reference document

Interstitial

加入 TADInterstitial

TADInterstitial 的用法與 TADBannerView 相似,簡單的步驟即可加入TADInterstitial 建議在 UIViewController 中執行以下步驟:

  • 匯入 import TAMediaAdsFramework
  • 在 UIViewController 中宣告 TADInterstitial 執行個體
  • 建立插頁式廣告
  • 設定廣告單元編號
  • 建立Request請求廣告

InterstitialViewController.swift

import TAMediaAdsFramework

class InterstitialViewController: UIViewController {

    var interstitialView: TADInterstitial?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        requestAd()
    }

    func requestAd() {
        self.resultLabel.text = "Loading..."

        let request = TADRequest()
        request.setLocationWithLatitude(25.02246916213678, longitude: 121.54834205241194, accuracy: 1)
        request.showLog = true
        interstitialView = TADInterstitial()
        interstitialView?.delegate = self

        //是否使用麥克風廣告 default為Yes,依需求修改 [註1]
        interstitialView?.turnOnMicrophone = false

        //讓廣告控制audioSessionControl default為Yes,依需求修改 [註2]
        interstitialView?.allowAudioSessionControl = true

        interstitialView?.adUnitID = [_YOUR_AD_UNIT_AD_]

        interstitialView?.load(request)
    }
}

TADInterstitialDelegate

extension InterstitialViewController: TADInterstitialDelegate {
    // 廣告取得成功,可以在此時間點及之後顯示呈現廣告
    func interstitialDidReceiveAd(_ ad: TADInterstitial!) {
        ad.present(fromRootViewController: self)
    }

    // 廣告取得失敗
    func interstitial(_ ad: TADInterstitial!, didFailToReceiveAdWithError error: TADRequestError!) {
    }

    // Interstitial廣告呈現之前呼叫, 注意使用者可能會在廣告內按下連結(網頁, AppStore, ...)而因此離開應用程式, 可以在這function中處理該暫停之項目
    func interstitialWillPresentScreen(_ ad: TADInterstitial!) {
    }

    // Interstitial廣告關閉, 在螢幕上消失之前呼叫, 再次提醒在Interstitail消失前, 必須將Interstitial及delegate設為nil (可以在這個function中執行)
    func interstitialWillDismissScreen(_ ad: TADInterstitial!) {
        self.interstitialView?.delegate = nil;
        self.interstitialView = nil;
    }

    // Interstitial廣告關閉, 在螢幕上消失之後呼叫
    func interstitialDidDismissScreen(_ ad: TADInterstitial!) {
    }

    // 使用者在廣告內按下連結(網頁, AppStore, ...)而因此離開應用程式之前呼叫
    func interstitialWillLeaveApplication(_ ad: TADInterstitial!) {
    }
}


[註1]TADBannerView 及 TADInterstitial增加此屬性,Default為YES。設為YES會去使用TADMicrophoneDetector物件,進而拿到麥克風類型廣告,與使用者互動,設為NO,則回傳server無Microphone。因為使用麥克風廣告會造成音樂類型的app中斷播放,建議音樂類型app在此設為NO。

[註2]allowAudioSessionControl設為YES以及原本app的AudioSession category為AVAudioSessionCategorySoloAmbient或AVAudioSessionCategoryPlayback時,將由SDK控制AudioSession設定active及改變category以滿足背景音樂中斷及續撥的行為。若是設為NO或category原本設定並非上述兩種SDK將不會去對AudioSession做改變,而是交給開發者在插頁出現及消失時,依據想要的行為做設定。


回 SDK 8首頁