Admob发布了新的SDK v6.2.1,过去几天我一直试图实现它而没有成功。 SDK中的google analytics addon 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,中介,搜索))时,项目都会编译。 但是如果我尝试实现GADBannerView(没有addons文件夹),则会出现缺少分析插件文件的Mach-O链接器错误。
cocos2d v1.X
Xcode v4.5.2
这里有什么我想念的吗?
*编辑*
似乎我包括了SDK下载中提供的所有内容,其中包括一个示例项目。在仅包含GAD类,libGoogleAdMobAds.a,README.txt和其他库(AdSupport.framework)之后,它编译得很好。希望有所帮助。
答案 0 :(得分: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;
}];
}
}
答案 1 :(得分:0)
似乎我包含了SDK下载中提供的所有内容,其中包括一个示例项目。在仅包含GAD类,libGoogleAdMobAds.a,README.txt和其他库(AdSupport.framework)之后,它编译得很好。希望有所帮助。
答案 2 :(得分:0)
我相信@autoreleasepool
仅在ARC下有效。如果您的项目未使用ARC,则可以仅使用-fobjc-arc
编译器标志为该文件启用它。 (或者,因为main.m
并没有真正做任何特别的事情,所以坚持使用你所拥有的那个。)