在包含广告的类中导入 Oyster
#import <Oyster/Oyster.h>
在 AppDelegate 中增加以下代码
#import <Oyster/Oyster.h>
@implementation AppDelegate
- (BOOL) application:(UIApplication*) application didFinishLaunchingWithOptions:(NSDictionary*) launchOptions {
// Override point for customization after application launch.
[Oyster initInstance];
return YES;
}
@end
OysterAdLoaderOptions* options = [[OysterAdLoaderOptions alloc] init];
options.imageSize = MIDDLE;
self.adLoader = [[OysterAdLoader alloc]
initWithAdUnitID:@"AD_UNIT_ID" rootViewController:rootViewController adTypes:@[kOysterAdLoaderAdTypeContent] options:options];
self.adLoader.delegate = self;
[self.adLoader loadRequest];
@interface YourController<OysterContentAdLoaderDelegate>
@end
@implementation YourController
// 失敗回傳
- (void) adLoader:(OysterAdLoader*) adLoader didFailToReceiveAdWithError:(NSError*) error;
// 成功回傳
- (void) adLoader:(OysterAdLoader*) adLoader didReceiveNativeContentAd:(OysterContentAd*) oysterContentAd;
@end
首先生成.xib 文件,点击 Utilities 出现在 Xcode 右侧边栏,选择左边数来第三项的 identity inspector 如下图
确定 Custom Class 有继承 OysterContentAdView。
接着即可生成5个 IBOutlet,如下图。
分别为 UILabel的 headerlineView作为广告的标题,UIImageView的imageView作为广告的内图,UILabel的bodyView作为广告的内文,UILabel的advertiserView作为广告的赞助商名称,UIImageView的logoView作为广告的 logo。
在制作好 xib 布局之后,在要执行的 ViewController 部分实现以下部分
- (void) adLoader:(OysterAdLoader*) adLoader didReceiveNativeContentAd:(OysterContentAd*) oysterContentAd {
OysterContentAdView* oysterContentAdView = [[[NSBundle mainBundle]
loadNibNamed:@"NativeContentAdView" owner:nil options:nil]
firstObject];
[self setAdView:oysterContentAdView];
oysterContentAdView.oysterContentAd = oysterContentAd;
((UILabel*) oysterContentAdView.headlineView).text = oysterContentAd.headline;
((UILabel*) oysterContentAdView.bodyView).text = oysterContentAd.headline;
((UILabel*) oysterContentAdView.advertiserView).text = oysterContentAd.advertiser;
((UIImageView*) oysterContentAdView.imageView).image = oysterContentAd.adImage.image;
((UIImageView*) oysterContentAdView.logoView).image = oysterContentAd.adLogo.image;
[((UIButton*) oysterContentAdView.callToAction) setTitle:oysterContentAd.callToAction forState:UIControlStateNormal];
}
- (void) viewDidLoad {
[super viewDidLoad];
self.oysterAdView.adUnitID = @"c145f1cd389e49a5";
self.oysterAdView.rootViewController = self;
[self.oysterAdView loadAds];
}
1.0.8