AdWhirl 3.0 + AdMob (iPhone+iPad App) 設置方法

AdWhirl 3.0 + AdMob (iPhone+iPad App) 設置方法

如果你正在尋找如何設置 AdWhirl SDK到XCode Project 可參看 AdWhirl 3.0 + AdMob (iPhone+iPad App) 設置方法

要 AdWhirl與 AdMob的支援你的Universal App,使其同時在iPhone和iPad正常顯示,首先需要在AdMob 及AdWhirl把App 加入成兩個單獨的App,一個用於 iPhone和一個 iPad的。故先轉到 AdMob的,添加App兩次,獲得將舉兩個Publisher ID。把這兩個Publisher ID在AdWhirl中在相應的App Profile 中設置。最後您將有兩個 AdWhirl App,一個是iPhone 的,另一個iPad的,並在每個其中,有相應的AdMob Publisher ID。

在 AdWhirlViewDelegate class 的 adWhirlApplicationKey method,傳回iPhone/iPad相應的AdWhirl SDK Key,如下(請把Your_AdWhirl_SDK_Key_for_iPhone和Your_AdWhirl_SDK_Key_for_iPad改成您兩個AdWhirl SDK Key):

//AdWhirlViewDelegate
- (Nsstring *)adWhirlApplicationKey {

    if (UI_USER_INTERFACE_IdioM() == UIUserInterfaceIdiomPhone)
    {
        return @"Your_AdWhirl_SDK_Key_for_iPhone";
    }
    else
    {
        return @"Your_AdWhirl_SDK_Key_for_iPad";
    }
}

在 AdWhirl SDK 3.0中的AdMob adapter “AdWhirlAdapterGoogleAdMobAds.m”,更改getAd() method:

在method 的開端加入:

  //Request the right size ad for your device
  CGSize adSize = GAD_SIZE_320x50;
  if (UI_USER_INTERFACE_IdioM() == UIUserInterfaceIdiomPad)
        adSize = GAD_SIZE_728x90;

  CGRect adFrame = CGRectMake(0,adSize.width,adSize.height);

在method 中找這一行

 GADBannerView *view = 
    [[GADBannerView alloc] initWithFrame:kAdWhirlViewDefaultFrame];

改成:

  GADBannerView *view =
    [[GADBannerView alloc] initWithFrame:adFrame];

以下是更改完成後的getAd() method:

- (void)getAd {

  //Request the right size ad for your device
  CGSize adSize = GAD_SIZE_320x50;
  if (UI_USER_INTERFACE_IdioM() == UIUserInterfaceIdiomPad)
        adSize = GAD_SIZE_728x90;

  CGRect adFrame = CGRectMake(0,adSize.height);

  GADRequest *request = [GADRequest request];
  NSObject *value;

  NSMutableDictionary *additional = [NSMutableDictionary dictionary];
  if ([adWhirlDelegate respondsToSelector:@selector(adWhirlTestMode)]
      && [adWhirlDelegate adWhirlTestMode]) {
    [additional setobject:@"on" forKey:@"adtest"];
  }

  if ((value = [self delegateValueForSelector:
                      @selector(adWhirlAdBackgroundColor)])) {
    [additional setobject:[self hexStringFromUIColor:(UIColor *)value]
                  forKey:@"color_bg"];
  }

  if ((value = [self delegateValueForSelector:
                      @selector(adWhirlAdBackgroundColor)])) {
    [additional setobject:[self hexStringFromUIColor:(UIColor *)value]
                   forKey:@"color_text"];
  }

  // deliberately don't allow other color specifications.

  if ([additional count] > 0) {
    request.additionalParameters = additional;
  }

  CLLocation *location =
      (CLLocation *)[self delegateValueForSelector:@selector(locationInfo)];

  if ((adWhirlConfig.locationOn) && (location)) {
    [request setLocationWithLatitude:location.coordinate.latitude
                           longitude:location.coordinate.longitude
                            accuracy:location.horizontalAccuracy];
  }

  Nsstring *string =
      (Nsstring *)[self delegateValueForSelector:@selector(gender)];

  if ([string isEqualToString:@"m"]) {
    request.gender = kGADGenderMale;
  } else if ([string isEqualToString:@"f"]) {
    request.gender = kGADGenderFemale;
  } else {
    request.gender = kGADGenderUnkNown;
  }

  if ((value = [self delegateValueForSelector:@selector(dateOfBirth)])) {
    request.birthday = (NSDate *)value;
  }

  if ((value = [self delegateValueForSelector:@selector(keywords)])) {
    request.keywords = [NSMutableArray arrayWithArray:(NSArray *)value];
  }

  GADBannerView *view =
    [[GADBannerView alloc] initWithFrame:adFrame];

  view.adUnitID = [self publisherId];
  view.delegate = self;
  view.rootViewController =
      [adWhirlDelegate viewControllerForPresentingModalView];

  self.adNetworkView = [view autorelease];

  [view loadRequest:request];
}

有了上面的設置和修改,iPhone 和iPad都能顯示正確的廣告尺寸,甚至iAD。

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...