1

Admob 发布了新的 SDK v6.2.1,在过去的几天里,我一直在尝试实现它,但没有成功。SDK 中的谷歌分析插件 main.m 有问题:

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 一起编译。每当我删除包含(DoubleClick、GoogleAnalyticsiOS_2.0beta3、Mediation、Search)的附加组件文件夹时,项目都会编译。但是如果我尝试实现 GADBannerView(没有插件文件夹),则会出现 Mach-O 链接器错误分析插件文件。

cocos2d v1.X
Xcode v4.5.2

我在这里缺少什么吗?

* 编辑 *
似乎我包含了 SDK 下载中提供的所有内容,其中包括一个示例项目。在仅包含 GAD 类、libGoogleAdMobAds.a、README.txt 和一个附加库 (AdSupport.framework) 之后,它编译得很好。希望有帮助。

4

3 回答 3

0

I believe @autoreleasepool is only valid under ARC. If your project isn't using ARC, you can enable it just for that file with the -fobjc-arc compiler flag. (Or, since that main.m doesn't really do anything special, stick with the one you've got.)

于 2013-01-19T08:44:53.210 回答
0

您可以在 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;

         }];
    }

}
于 2013-01-19T04:47:46.527 回答
0

似乎我包含了 SDK 下载中提供的所有内容,其中包括一个示例项目。在仅包含 GAD 类、libGoogleAdMobAds.a、README.txt 和一个附加库 (AdSupport.framework) 之后,它编译得很好。希望有帮助。

于 2013-01-19T07:43:22.037 回答