Rover12421's Blog

The End.

IOS添加AdMob广告测试—-XCode项目测试

        新建一个名为AdMobBannerSingle View Application 项目,进行测试吧.

        AdMobBanner

        新建好项目,把下载的SDK解压到项目目录(也可以是其他目录)里,并在项目上右键,添加文件,把解压的文件夹添加进来.
Add Files
        到这一部就可以写测试代码了,编译问题一会再说.代码不多,直接上代码截图吧,懒的弄高亮了:
头文件ViewController.h:
ViewController.h
源文件ViewController.m:
ViewController.m
        其中红色框起来的代码是新添加的代码.现在关键的时刻来了.cmd+b编译吧.
        哈哈,22个错误.你没看错的.
err 22
        接下来添加依赖库吧:
       TARGETS-->Build Phases-->Link Binary With Libraries 
       点+号添加以下6个库:

AudioToolbox.framework
CoreData.framework
MessageUI.framework
StoreKit.framework
AdSupport.framework
SystemConfiguration.framework

add libraries
        再次编译,只有一个错误了:
duplicate symbol _OBJC_CLASS_$_AppDelegate in:
    /Users/Rover12421/Library/Developer/Xcode/DerivedData/AdMobBanner-acmnubaksfhpkvdhcqtxfafheoky/Build/Intermediates/AdMobBanner.build/Debug-iphonesimulator/AdMobBanner.build/Objects-normal/i386/AppDelegate-9B5779F422466467.o
    /Users/Rover12421/Library/Developer/Xcode/DerivedData/AdMobBanner-acmnubaksfhpkvdhcqtxfafheoky/Build/Intermediates/AdMobBanner.build/Debug-iphonesimulator/AdMobBanner.build/Objects-normal/i386/AppDelegate-D5DB0C40CA55C346.o
duplicate symbol _OBJC_METACLASS_$_AppDelegate in:
    /Users/Rover12421/Library/Developer/Xcode/DerivedData/AdMobBanner-acmnubaksfhpkvdhcqtxfafheoky/Build/Intermediates/AdMobBanner.build/Debug-iphonesimulator/AdMobBanner.build/Objects-normal/i386/AppDelegate-9B5779F422466467.o
    /Users/Rover12421/Library/Developer/Xcode/DerivedData/AdMobBanner-acmnubaksfhpkvdhcqtxfafheoky/Build/Intermediates/AdMobBanner.build/Debug-iphonesimulator/AdMobBanner.build/Objects-normal/i386/AppDelegate-D5DB0C40CA55C346.o
duplicate symbol _main in:
    /Users/Rover12421/Library/Developer/Xcode/DerivedData/AdMobBanner-acmnubaksfhpkvdhcqtxfafheoky/Build/Intermediates/AdMobBanner.build/Debug-iphonesimulator/AdMobBanner.build/Objects-normal/i386/main-6DC86324021DB45C.o
    /Users/Rover12421/Library/Developer/Xcode/DerivedData/AdMobBanner-acmnubaksfhpkvdhcqtxfafheoky/Build/Intermediates/AdMobBanner.build/Debug-iphonesimulator/AdMobBanner.build/Objects-normal/i386/main-511ABFCDEBEDD547.o
ld: 3 duplicate symbols for architecture i386

clang: error: linker command failed with exit code 1 (use -v to see invocation)

        这次需要删除SDK中关于广告分析部分的代码(删除代码或删除引用都行).我这里的名称是:GooleAnalyticsiOS_2.0beta4 .再次编译,通过了.cmd+r运行试试.
Del SDk Analytics Code
        黑屏,崩溃了?是的.
2013-05-08 16:43:52.880 AdMobBanner[3245:c07] To get test ads on this device, call: request.testDevices = [NSArray arrayWithObjects:@"GAD_SIMULATOR_ID", nil];
2013-05-08 16:43:52.885 AdMobBanner[3245:c07] -[GADObjectPrivate changeState:]: unrecognized selector sent to instance 0xa646f10
2013-05-08 16:43:52.887 AdMobBanner[3245:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[GADObjectPrivate changeState:]: unrecognized selector sent to instance 0xa646f10'
*** First throw call stack:
(0x1c81012 0x19f4e7e 0x1d0c4bd 0x1c70bbc 0x1c7094e 0x17ae5 0x19959 0x17008 0x309a 0xa1a1c7 0xa1a232 0x9693d5 0x96976f 0x969905 0x972917 0x93696c 0x93794b 0x948cb5 0x949beb 0x93b698 0x2a8adf9 0x2a8aad0 0x1bf6bf5 0x1bf6962 0x1c27bb6 0x1c26f44 0x1c26e1b 0x93717a 0x938ffc 0x2d32 0x2c65)
libc++abi.dylib: terminate called throwing an exception
(lldb) 

carsh
       接下来进行最后一步配置操作(真的是最后一步了么.....):
       TARGETS-->Build Settings-->Other Linker Flags
       添加选项 -ObjC
Other linker Flags
        cmd+r,编译运行,正常了吧.
        ???效果不对...确实哦,尺寸多了...原来是代码写错了....提示里已经很清楚了...
2013-05-08 16:54:56.396 AdMobBanner[3336:c07] To get test ads on this device, call: request.testDevices = [NSArray arrayWithObjects:@"GAD_SIMULATOR_ID", nil];
2013-05-08 16:54:56.606 AdMobBanner[3336:c07] Warning (banner size mismatch): Attempting to request kGADAdSizeMediumRectangle but server configuration was for kGADAdSizeBanner.

Run Result
        把

bannerView_ = [[GADBannerView alloc]initWithAdSize:kGADAdSizeMediumRectangle];

        修改为:

bannerView_ = [[GADBannerView alloc]initWithAdSize:kGADAdSizeBanner];

       这下正常了.
kGADAdSizeBanner

Comments