2012-07-30 89 views
1

我想在我的ios應用程序中添加admob。Xcode 4.4與admod

我必須遵循教程:

https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals?hl=en#ios

不過,即使樣本項目或在我的代碼IOS項目添加源代碼,我有一個錯誤:

*終止應用程序由於未捕獲的異常'NSInvalidArgumentException',原因:' - [GADBannerView private]:無法識別的選擇器發送到實例0x1727d0'

因此源代碼:

ViewController.h

#import <UIKit/UIKit.h> 
#import "GADBannerView.h" 

@interface ViewController : UIViewController{ 
    GADBannerView *bannerView_; 
} 

@end 

而且

ViewController.m

#import "ViewController.h" 

@interface ViewController() 

@end 

@implementation ViewController 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Create a view of the standard size at the bottom of the screen. 
    bannerView_ = [[GADBannerView alloc] 
        initWithFrame:CGRectMake(0.0, 
              self.view.frame.size.height - 
              GAD_SIZE_320x50.height, 
              GAD_SIZE_320x50.width, 
              GAD_SIZE_320x50.height)]; 

    // Specify the ad's "unit identifier." This is your AdMob Publisher ID. 
    bannerView_.adUnitID = @"MYID"; 

    // Let the runtime know which UIViewController to restore after taking 
    // the user wherever the ad goes and add it to the view hierarchy. 
    bannerView_.rootViewController = self; 
    [self.view addSubview:bannerView_]; 

    // Initiate a generic request to load it with an ad. 
    [bannerView_ loadRequest:[GADRequest request]]; 
} 

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 
     return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 
    } else { 
     return YES; 
    } 
} 

@end 
+0

你有沒有弄清楚這是爲什麼崩潰。我遇到了同樣的問題。 – David 2012-07-30 19:56:43

回答

1

如果您已經添加-all_load,它仍然沒有工作:

  1. 關閉了XCode,以確保正確關閉它。
  2. 重新打開XCode。
  3. 清理項目。
  4. 構建。

好運:)