Admob的新SDK是否与cocos2d兼容?



Admob发布了新的SDK v6.2.1,在过去的几天里,我一直在尝试实现它,但没有成功。有一些错误的谷歌分析插件主要。

Error 1: Stray '@' in program
Error 2: 'autoreleasepool' undeclared (first use in this function)
Error 3: Expected ';' before '{' token
main.m file:
//
// main.m
// CuteAnimals
//
// Copyright 2012 Google, Inc. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char *argv[]) {
    @autoreleasepool {
       return UIApplicationMain(argc, argv, nil,
             NSStringFromClass([AppDelegate class]));
    }
}

我已经链接了所有需要的库:

AudioToolbox.framework
MessageUI.framework
AVFoundation.framework
StoreKit.framework
iAd.framework
SystemConfiguration.framework
QuartzCore.framework
OpenGLES.framework
OpenAL.framework
UIKit.framework
Foundation.framework
CoreGraphics.framework
libGoogleAdMobAds.a
libGoogleAnalytics.a
libGoogleAnalytics_debug.a

我甚至还没有包括或实现GAdbannerView。该项目甚至不能在包含SDK的情况下编译。每当我删除Add-ons文件夹,其中包括(DoubleClick, GoogleAnalyticsiOS_2.0beta3, Mediation, Search),项目编译…但是,如果我尝试实现GADBannerView,(没有插件文件夹),Mach-O链接器错误出现丢失的分析插件文件。

cocos2d v1.X
Xcode v4.5.2

我在这里错过了什么吗?

* EDIT *
似乎我包括了SDK下载中提供的所有内容,其中包括一个示例项目。只包括GAD类之后,libGoogleAdMobAds。a、README.txt和一个额外的库(AdSupport.framework),它可以很好地编译。

你可以在cocos2d游戏中使用admob。下面是工作代码:

@interface MyMainMenu : CCLayer
{
    GADBannerView *mBannerView;
}
@implementation MyMainMenu

-(void)onEnter
{
    [super onEnter];
    [self createAdmobAds];
}
-(void)createAdmobAds
{
    AppController *app =  (AppController*)[[UIApplication sharedApplication] delegate];    
    // Create a view of the standard size at the bottom of the screen.
    // Available AdSize constants are explained in GADAdSize.h.
    mBannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerLandscape];
    // Specify the ad's "unit identifier." This is your AdMob Publisher ID.
    mBannerView.adUnitID = MY_BANNER_UNIT_ID;
    // Let the runtime know which UIViewController to restore after taking
    // the user wherever the ad goes and add it to the view hierarchy.
    mBannerView.rootViewController = app.navController;
    [app.navController.view addSubview:mBannerView];
    // Initiate a generic request to load it with an ad.
    [mBannerView loadRequest:[GADRequest request]];
    CGSize s = [[CCDirector sharedDirector] winSize];
    CGRect frame = mBannerView.frame;
    frame.origin.y = s.height;
    frame.origin.x = (s.width/2.0f - frame.size.width/2.0f);
    mBannerView.frame = frame;
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    frame = mBannerView.frame;
    frame.origin.y = s.height - frame.size.height;
    frame.origin.x = (s.width/2.0f - frame.size.width/2.0f);
    mBannerView.frame = frame;
    [UIView commitAnimations];    
}

-(void)showBannerView
{
    if (mBannerView) 
    {
        [UIView animateWithDuration:0.5
                              delay:0.1
                            options: UIViewAnimationCurveEaseOut
                         animations:^
         {
             CGSize s = [[CCDirector sharedDirector] winSize];
             CGRect frame = mBannerView.frame;
             frame.origin.y = s.height - frame.size.height;
             frame.origin.x = (s.width/2.0f - frame.size.width/2.0f);
             mBannerView.frame = frame;
         } 
                         completion:^(BOOL finished)
         {
         }];
    }
}

-(void)hideBannerView
{
    if (mBannerView) 
    {
        [UIView animateWithDuration:0.5
                              delay:0.1
                            options: UIViewAnimationCurveEaseOut
                         animations:^
         {
             CGSize s = [[CCDirector sharedDirector] winSize];
             CGRect frame = mBannerView.frame;
             frame.origin.y = frame.origin.y +  frame.size.height;
             frame.origin.x = (s.width/2.0f - frame.size.width/2.0f);
         } 
                         completion:^(BOOL finished)
         {
         }];
    }
}

-(void)dismissAdView
{
    if (mBannerView) 
    {
        [UIView animateWithDuration:0.5
                              delay:0.1
                            options: UIViewAnimationCurveEaseOut
                         animations:^
         {
             CGSize s = [[CCDirector sharedDirector] winSize];
             CGRect frame = mBannerView.frame;
             frame.origin.y = frame.origin.y + frame.size.height ;
             frame.origin.x = (s.width/2.0f - frame.size.width/2.0f);
             mBannerView.frame = frame;
         } 
                         completion:^(BOOL finished)
         {
             [mBannerView setDelegate:nil];
             [mBannerView removeFromSuperview];
             mBannerView = nil;
         }];
    }
}

似乎我包括了SDK下载中提供的所有内容,其中包括一个示例项目。只包括GAD类之后,libGoogleAdMobAds。a、README.txt和一个额外的库(AdSupport.framework),它可以很好地编译。希望这对你有所帮助。

我相信@autoreleasepool只在ARC下有效。如果你的项目没有使用ARC,你可以用-fobjc-arc编译器标志为那个文件启用它。(或者,因为main.m没有什么特别的,坚持你已经得到的。)

最新更新