2016-07-28 59 views
0

我想在我的選項卡式應用中添加橫幅廣告,但我無法做到。 如何實現橫幅添加? 這是我tried-如何在swift中實施Google AdMobs橫幅廣告?

import UIKit 
import GoogleMobileAds 

class ViewController: UIViewController { 

var banner : GADBannerView! 

override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib. 
    loadBanner() 
} 

func loadBanner(){ 
    banner = GADBannerView(adSize: kGADAdSizeSmartBannerPortrait) 
    banner.adUnitID = "my_app_id" 
    banner.rootViewController = self 
    let req : GADRequest = GADRequest() 
    banner.loadRequest(req) 
    banner.frame = CGRectMake(0, view.bounds.height - banner.frame.size.height, banner.frame.size.width, banner.frame.size.height) 
    self.view.addSubview(banner) 
} 

回答

0

如果你想測試AdMob聯播集成,必須指定在了GADRequest對象的testDevices這樣的:

var request = GADRequest() 
request.testDevices = [GAD_SIMULATOR_ID]; 

在陣列的testDevices你可以把還您正在測試的手機的UUID。

另外,您是否從here開始執行步驟?他們是不同的東西。

你應該把下面的調用在didFinishLaunchingWithOptionsMethod:

GADMobileAds.configureWithApplicationID("YOUR_APPLICATION_ID"); 

不要AD_UNIT_ID搞錯APPLICATION_ID!