Created
January 11, 2011 05:34
-
-
Save marshluca/774068 to your computer and use it in GitHub Desktop.
Ads.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ItemWebViewController.m | |
// Woyi | |
// | |
// Created by wang xuefeng on 10-9-27. | |
// Copyright 2010 5Yi.com. All rights reserved. | |
// | |
#import "MUtility.h" | |
#import "WoyiAppDelegate.h" | |
#import "ItemWebViewController.h" | |
#import "AdChinaView.h" | |
#import "AdMobView.h" | |
#import "MobiSageSDK.h" | |
#import "GoogleAnalytics.h" | |
@implementation ItemWebViewController | |
- (id)initWithDict:(NSDictionary *)dict | |
{ | |
if (self = [super init]) { | |
self.title = @"新闻"; | |
self.hidesBottomBarWhenPushed = YES; | |
} | |
currentDict = dict; | |
[GoogleAnalytics AddAnalyticsForPage:@"新闻页面"]; | |
return self; | |
} | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
[self loadWebView]; | |
[self loadAdvertise]; | |
} | |
- (void)loadWebView | |
{ | |
webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 436)]; | |
webView.opaque = YES; | |
[webView loadHTMLString:[currentDict objectForKey:@"description"] | |
baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]]; | |
[self.view addSubview:webView]; | |
self.view.backgroundColor = [UIColor whiteColor]; | |
} | |
- (void)loadAdvertise | |
{ | |
NSDictionary *adConfigDict = [[NSUserDefaults standardUserDefaults] objectForKey:@"adConfig"]; | |
int mobiSageNumber = [[adConfigDict objectForKey:@"adsage"] intValue]; | |
int adChinaNumber = [[adConfigDict objectForKey:@"adchina"] intValue]; | |
int admobNumber = [[adConfigDict objectForKey:@"admob"] intValue]; | |
int adsenseNumber = [[adConfigDict objectForKey:@"adsense"] intValue]; | |
int num = [MUtility randomNumber]; | |
if (num % 100 < mobiSageNumber) { | |
[self loadMobiSage]; | |
} else if (num < adChinaNumber+mobiSageNumber) { | |
[self loadAdChina]; | |
} else if (num < admobNumber + adChinaNumber + mobiSageNumber) { | |
[self loadAdmob]; | |
} else if (num < adsenseNumber + admobNumber + adChinaNumber + mobiSageNumber) { | |
[self loadGoogleAds]; | |
} | |
} | |
// -----------------------------------------------mobisage ok------------------------------------------------------------------- | |
- (void)loadMobiSage | |
{ | |
MobiSageAdView* adView = [[MobiSageAdViewManager getInstance] createMobiSageAdView:Ad_320X48]; | |
[adView setRootViewController:self.navigationController]; | |
adView.frame = CGRectMake(0, 480-48-44, 320, 48); | |
[adView changeUpdateType:Fast_Update]; | |
[self.view addSubview:adView]; | |
[adView setCustomData:@"Hello world"]; | |
[adView release]; | |
webView.frame = CGRectMake(0,0,320,480-44-48); | |
} | |
// ------------------------------------------adchina ok------------------------------------------------------------------------ | |
- (void)loadAdChina | |
{ | |
if (adChinaAd) { | |
[adChinaAd removeFromSuperview]; | |
} | |
adChinaAd = [AdChinaView requestAdWithDelegate:self]; | |
[adChinaAd setAdPosAtY:480-44-64 size:AdSize]; | |
[self.view addSubview:adChinaAd]; | |
} | |
#pragma mark - | |
#pragma mark AdChinaDelegate methods | |
- (NSString *)adSpaceId:(AdChinaView *)adView | |
{ | |
// test: 69327; product: 69848 | |
return @"69848"; | |
} | |
- (void)didGetAd:(AdChinaView *)adView | |
{ | |
webView.frame = CGRectMake(0, 0, 320, 480-44-64); | |
NSLog(@"AdChina: Did receive ad"); | |
} | |
- (void)didFailToGetAd:(AdChinaView *)adView | |
{ | |
NSLog(@"AdChina: Failed to receive ad"); | |
} | |
- (void)didClickOnAd:(AdChinaView *)adView | |
{ | |
NSLog(@"AdChina: Did click on an ad"); | |
} | |
- (void)didBackFromAdWeb:(AdChinaView *)adView | |
{ | |
NSLog(@"AdChina: Did back from ad web"); | |
} | |
// --------------------------------Admob ok---------------------------------------------------------------------------------- | |
- (void)loadAdmob | |
{ | |
adMobAd = [AdMobView requestAdWithDelegate:self]; | |
[adMobAd retain]; // this will be released when it loads (or fails to load) | |
} | |
#pragma mark - | |
#pragma mark AdMobDelegate methods | |
- (NSString *)publisherIdForAd:(AdMobView *)adView | |
{ | |
return @"a14ca51631af9b5"; | |
} | |
- (UIViewController *)currentViewControllerForAd:(AdMobView *)adView | |
{ | |
return self; | |
} | |
- (void)didReceiveAd:(AdMobView *)adView | |
{ | |
webView.frame = CGRectMake(0, 0, 320, 480-44-44); | |
adMobAd.frame = CGRectMake(0, 480-44-44, 320, 44); | |
adMobAd.backgroundColor = [UIColor blackColor]; | |
[self.view addSubview:adMobAd]; | |
NSLog(@"AdMob: Did receive ad"); | |
} | |
- (void)didFailToReceiveAd:(AdMobView *)adView | |
{ | |
[adMobAd removeFromSuperview]; | |
[adMobAd release]; | |
adMobAd = nil; | |
NSLog(@"AdMob: Did fail to receive ad"); | |
} | |
// -----------------------------------------------google adsense ok------------------------------------------------------------------- | |
#define SHOW_300x250_AD 0 | |
- (void)loadGoogleAds | |
{ | |
adViewController_ = [[GADAdViewController alloc] initWithDelegate:self]; | |
#if SHOW_300x250_AD | |
adViewController_.adSize = kGADAdSize300x250; | |
#else | |
adViewController_.adSize = kGADAdSize320x50; | |
#endif | |
// ************************************************************************** | |
// Please replace the kGADAdSenseCompanyName, kGADAdSenseAppName and | |
// kGADAdSenseApplicationAppleID with your own company name, application name, | |
// and Application Apple ID respectively. | |
// | |
// Also, replace the kGADAdSenseKeywords and kGADAdSenseChannelIDs values with | |
// your own keywords, and channel IDs, respectively. If this application has | |
// an associated iPhone website, then set the site's URL using | |
// kGADAdSenseAppWebContentURL for improved ad targeting. | |
// | |
// PLEASE DO NOT CLICK ON THE AD UNLESS YOU ARE IN TEST MODE. OTHERWISE, YOUR | |
// ACCOUNT MAY BE DISABLED. | |
// ************************************************************************** | |
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys: | |
@"ca-mb-app-pub-5252709778530918", kGADAdSenseClientID, | |
@"北京我易科技", kGADAdSenseCompanyName, | |
@"理财新闻", kGADAdSenseAppName, | |
@"411101929", kGADAdSenseApplicationAppleID, | |
@"理财+投资+股票+基金+外汇+银行理财+债券+期货", kGADAdSenseKeywords, | |
[NSArray arrayWithObjects:@"3721124283", nil], kGADAdSenseChannelIDs, | |
[NSNumber numberWithInt:1], kGADAdSenseIsTestAdRequest, | |
nil]; | |
// Loading the ad will create the ad view. | |
[adViewController_ loadGoogleAd:attributes]; | |
// Position ad at bottom of screen. | |
UIView *adView = adViewController_.view; | |
CGFloat adViewHeight = [adView bounds].size.height; | |
CGRect bounds = [self.view bounds]; | |
CGPoint center = CGPointMake(CGRectGetMidX(bounds),CGRectGetMaxY(bounds) - adViewHeight / 2); | |
[adView setCenter:center]; | |
adView.frame = CGRectMake(0, 480-44-50, 320, 50); | |
[self.view addSubview:adView]; | |
} | |
- (UIViewController *)viewControllerForModalPresentation:(GADAdViewController *)adController | |
{ | |
return self; | |
} | |
- (GADAdClickAction)adControllerActionModelForAdClick:(GADAdViewController *)adController | |
{ | |
return GAD_ACTION_DISPLAY_INTERNAL_WEBSITE_VIEW; | |
} | |
- (void)loadSucceeded:(GADAdViewController *)adController withResults:(NSDictionary *)results | |
{ | |
webView.frame = CGRectMake(0, 0, 320, 480-44-50); | |
NSLog(@"Google Adsense Succeeded"); | |
} | |
// ------------------------------------------------------------------------------------------------------------------ | |
/* | |
// Override to allow orientations other than the default portrait orientation. | |
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { | |
// Return YES for supported orientations | |
return (interfaceOrientation == UIInterfaceOrientationPortrait); | |
} | |
*/ | |
- (void)didReceiveMemoryWarning { | |
// Releases the view if it doesn't have a superview. | |
[super didReceiveMemoryWarning]; | |
// Release any cached data, images, etc that aren't in use. | |
} | |
- (void)viewDidUnload { | |
[super viewDidUnload]; | |
// Release any retained subviews of the main view. | |
// e.g. self.myOutlet = nil; | |
} | |
- (void)dealloc { | |
[webView release]; | |
[super dealloc]; | |
} | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ItemWebViewController.h | |
// Woyi | |
// | |
// Created by wang xuefeng on 10-9-27. | |
// Copyright 2010 5Yi.com. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> | |
#import "AdChinaDelegateProtocol.h" | |
#import "AdMobDelegateProtocol.h" | |
#import "GADAdViewController.h" | |
#import "GADAdSenseParameters.h" | |
@class AdChinaView; | |
@class AdMobView; | |
@interface ItemWebViewController : UIViewController <AdChinaDelegate,GADAdViewControllerDelegate,AdMobDelegate> | |
{ | |
NSDictionary *currentDict; | |
UIWebView *webView; | |
AdChinaView *adChinaAd; | |
AdMobView *adMobAd; | |
GADAdViewController *adViewController_; | |
} | |
- (id)initWithDict:(NSDictionary *)dict; | |
- (void)loadWebView; | |
- (void)loadAdvertise; | |
- (void)loadAdChina; | |
- (void)loadAdmob; | |
- (void)loadGoogleAds; | |
- (void)loadMobiSage; | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment