我正在爲react-native中的Google DFP構建原生視圖。我真的很接近我的成功,但一個小東西丟失:(原生ios在React Native中查看
DFPAdViewManager.m:
#import "DFPAdView.h"
#import <UIKit/UIKit.h>
#import "DFPAdViewManager.h"
@implementation DFPAdViewManager
RCT_EXPORT_MODULE();
RCT_EXPORT_VIEW_PROPERTY(adUnitId, NSString)
RCT_EXPORT_VIEW_PROPERTY(adHeight, int)
RCT_EXPORT_VIEW_PROPERTY(adWidth, int)
- (UIView *)view
{
DFPAdView * theView;
theView = [[DFPAdView alloc] init];
return theView;
}
@end
DFPAdView.m:
#import "DFPAdView.h"
@import GoogleMobileAds;
@implementation DFPAdView
{
DFPBannerView *bannerView;
}
- (instancetype)init
{
self = [super init];
bannerView = [DFPBannerView alloc];
return self;
}
- (void)setAdHeight:(int*)adHeight
{
self.adHeight = adHeight;
}
- (void)setAdWidth:(int*)adWidth
{
self.adWidth = adWidth;
}
- (void)setAdUnitId:(NSString*)adUnitId
{
GADAdSize customAdSize = GADAdSizeFromCGSize(CGSizeMake(self.adWidth, self.adHeight));
bannerView = [[DFPBannerView alloc] initWithAdSize:customAdSize];
[self addSubview:bannerView];
UIViewController *controller = [[UIViewController alloc] init];
bannerView.adUnitID = adUnitId;
bannerView.rootViewController = controller;
DFPRequest *request = [DFPRequest request];
[bannerView loadRequest:request];
}
@end
我的問題是如何創造我的bannerView與我從JavaScript獲得的adHeight和adWidth大小有關嗎?我認爲它只是Objective-C代碼中的一點變化,但我只是不知道,也沒有找到辦法做到這一點。如果有人能幫助我。謝謝
嘿!這個問題你有沒有進一步的瞭解?想分享結果嗎? – ptomasroos
是的,我做了一個解決方案。它與上面有點不同,但它工作正常。我會用一個答案來形容它;-) – vanBrunneren
請幫助我!向我展示所有代碼,因爲我需要在我的應用中顯示DFP廣告管理系統 – stereodenis