xcode 6 快速广告 GoogleMobileAdsSdkiOS

xcode 6 swift ads GoogleMobileAdsSdkiOS(xcode 6 快速广告 GoogleMobileAdsSdkiOS)
本文介绍了xcode 6 快速广告 GoogleMobileAdsSdkiOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Xcode 6 + Swift.

I'm using Xcode 6 + Swift.

有人知道如何在 Swift 项目中集成 Google AdsGoogleMobileAdsSdkiOS?如何配置,如何编程?

Does anybody know how to integrate Google Ads, GoogleMobileAdsSdkiOS on a Swift Project? how to config, and how to program?

我在项目上新建了一个文件Teste-Bridging-Header.h,把#import GADBannerView.h基于 这个参考

I created a new file Teste-Bridging-Header.h on the project and put #import GADBannerView.h based on this reference

在我的 ViewController.swift 上类似:

class ViewController: UIViewController {   
     override func viewDidAppear(animated: Bool)  {
        super.viewWillAppear(animated)    

        var adB = GADBannerView()
        adB.delegate = self
        adB.rootViewController = self
        adB.adUnitID =  MY_ADS_ID //"ca-app-pub-XXXXXXXX/XXXXXXX"       
     }
}

我的方向正确吗?我可以举一些例子吗?

now its working...

on .h created  Objective-C bridging header I put: 
#import "GADBannerView.h"
#import "GADBannerViewDelegate.h"
#import "GADRequest.h"

my swift file:

    class ViewController: UIViewController, GADBannerViewDelegate {

         override func viewDidAppear(animated: Bool)  {
            super.viewWillAppear(animated)

            var adB = GADBannerView( frame:CGRectMake(0, 0, 320, 50) )
            adB.delegate = self
            adB.rootViewController = self
            adB.adUnitID = "ca-app-pub-XXXXXXX/XXXXXXXX"

            var reqAdB = GADRequest()
            //reqAdB.testDevices = [ GAD_SIMULATOR_ID ] //not working, dont know why
            //reqAdB.testDevices = ["Simulator"] //not working, dont know why

            adB.loadRequest(reqAdB)        
            self.view.addSubview(adB)

         }

    }

推荐答案

我设法通过使用这个来编译和工作:

I managed to get everything compiling and working by using this:

override func viewDidAppear(animated: Bool)  {
    super.viewDidAppear(animated)

    var origin = CGPointMake(0.0,
        self.view.frame.size.height -
            CGSizeFromGADAdSize(kGADAdSizeBanner).height); // place at bottom of view

    var size = GADAdSizeFullWidthPortraitWithHeight(50) // set size to 50
    var adB = GADBannerView(adSize: size, origin: origin) // create the banner
    adB.adUnitID = MY_BANNER_UNIT_ID  //"ca-app-pub-XXXXXXXX/XXXXXXX"
    adB.delegate = self // ??
    adB.rootViewController = self // ??
    self.view.addSubview(adB) // ??
    var request = GADRequest() // create request
    request.testDevices = [ GAD_SIMULATOR_ID ]; // set it to "test" request
    adB.loadRequest(request) // actually load it (?)
}

为了让它工作,我必须确保在Swift 编译器 - 代码生成"部分中包含_-Bridging-Header.h"(带有您的项目名称),"Objective-C Bridging Header"字段(按照原贴的建议).

To get it to work, I had to make sure to include "_-Bridging-Header.h" (with your project name) in the "Swift Compiler - Code Generation" section, "Objective-C Bridging Header" field (as original posted suggested).

这篇关于xcode 6 快速广告 GoogleMobileAdsSdkiOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
Dropbox Files.download does not start when number of files in folder is gt; 1000(当文件夹中的文件数为1000时,Dropbox Files.Download不会启动)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)