Ios-iad-integration
提供:Dev Guides
iOS-iAd統合
iAdは、アップルサーバーによって配信される広告の表示に使用されます。 iAdは、iOSアプリケーションから収益を得るのに役立ちます。
iAd統合-関与するステップ
- ステップ1 *-シンプルなビューベースのアプリケーションを作成します。
- ステップ2 *-プロジェクトファイルを選択し、ターゲットを選択して、フレームワークの選択でiAd.frameworkを追加します。
- ステップ3 *-次のようにViewController.hを更新します-
#import <UIKit/UIKit.h>
#import <iAd/iAd.h>
@interface ViewController : UIViewController<ADBannerViewDelegate> {
ADBannerView *bannerView;
}
@end
ステップ4 *-次のように *ViewController.m を更新します-
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
bannerView = [[ADBannerView alloc]initWithFrame:
CGRectMake(0, 0, 320, 50)];
//Optional to set background color to clear color
[bannerView setBackgroundColor:[UIColor clearColor]];
[self.view addSubview: bannerView];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
//Dispose of any resources that can be recreated.
}
#pragma mark - AdViewDelegates
-(void)bannerView:(ADBannerView *)banner
didFailToReceiveAdWithError:(NSError *)error {
NSLog(@"Error loading");
}
-(void)bannerViewDidLoadAd:(ADBannerView *)banner {
NSLog(@"Ad loaded");
}
-(void)bannerViewWillLoadAd:(ADBannerView *)banner {
NSLog(@"Ad will load");
}
-(void)bannerViewActionDidFinish:(ADBannerView *)banner {
NSLog(@"Ad did finish");
}
@end
出力
アプリケーションを実行すると、次の出力が得られます-