TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Nov 2016 |
在有用到廣告的class匯入Oyster
#import <Oyster/Oyster.h>
在appdelegate增加以下的code
#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作為廣告的內文,UILable的advertiserView作為廣告的贊住商名稱,UIImageView的logoView作為廣告的 logo。
在製作好xib layout之後,在要執行的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