Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

你好,能咨询一下其他广告继承的思路吗?像banner广告什么的 #1

Open
wuweijian1997 opened this issue Mar 17, 2020 · 9 comments

Comments

@wuweijian1997
Copy link

像这种嵌入rn里的广告该如何继承呢?可以使用返回原生组件的方式访问广告吗?
image

@miracledan
Copy link
Member

@wuweijian1997 是的,可以用原生UI组件的方式来集成。
你先把穿山甲的demo在android studio里面跑起来,这个可以方便读懂源码。
你贴的这个应该是信息流广告,对应feed那个例子。把源码里面渲染view的代码移植到你的原生UI组件里面就行了。
RN官方文档:原生UI组件

@wuweijian1997
Copy link
Author

wuweijian1997 commented Mar 18, 2020

大佬能再请教一下我这样写为什么不行吗?没有报错,但是RN哪里没有展示,log如下图

@ReactModule(name = RNViewModule.REACT_CLASS)
public class RNViewModule extends SimpleViewManager<View> {
    private final static String TAG = "RN_VIEW_MODULE";
    protected static final String REACT_CLASS = "RNView";
    private TTAdNative mTTAdNative;
    private TTNativeExpressAd mTTAd;
    private Context mContext;
    public RNViewModule() {
        super();
    }

    private View resultView;

    @Override
    public String getName() {
        return REACT_CLASS;
    }

    @Override
    protected View createViewInstance(final ThemedReactContext reactContext) {
        mTTAdNative = TTAdManagerHolder.get().createAdNative(reactContext);
        mContext = reactContext;
        AdSlot adSlot = new AdSlot.Builder()
                .setCodeId("coddId") //广告位id
                .setSupportDeepLink(true)
                .setAdCount(1) //请求广告数量为1到3条
                .setExpressViewAcceptedSize(600,300) //期望模板广告view的size,单位dp
                .build();

        mTTAdNative.loadBannerExpressAd(adSlot, new TTAdNative.NativeExpressAdListener() {

            @Override
            public void onError(int code, String message) {
                Log.e(TAG, "onError " + code + " " + message);
            }

            @Override
            public void onNativeExpressAdLoad(List<TTNativeExpressAd> ads) {
                if (ads == null || ads.size() == 0){
                    return;
                }
                mTTAd = ads.get(0);
                bindAdListener(mTTAd);
                mTTAd.render();
            }
        });
        if(resultView == null) {
            Log.i(TAG, "IS NULL");
            resultView = new View(reactContext);
            return resultView;
        }
        Log.i(TAG, "IS NOT NULL");
        return resultView;
    }
    private void bindAdListener(TTNativeExpressAd ad) {
        ad.setExpressInteractionListener(new TTNativeExpressAd.ExpressAdInteractionListener() {
            @Override
            public void onAdClicked(View view, int type) {
                TToast.show(mContext, "广告被点击");
            }

            @Override
            public void onAdShow(View view, int type) {
                TToast.show(mContext, "广告展示");
            }

            @Override
            public void onRenderFail(View view, String msg, int code) {
                Log.e("ExpressView","render fail:"+(System.currentTimeMillis() ));
                TToast.show(mContext, msg+" code:"+code);
            }

            @Override
            public void onRenderSuccess(View view, float width, float height) {
                Log.e("ExpressView","render suc:"+(System.currentTimeMillis() ));
                //返回view的宽高 单位 dp
                TToast.show(mContext, "渲染成功");
                resultView = view;
                Log.i(TAG, resultView.toString());
            }
        });

LOG
`
2020-03-18 16:39:52.965 13066-13066/com.test I/RN_VIEW_MODULE: IS NULL
2020-03-18 16:39:53.793 13066-13066/com.test I/RN_VIEW_MODULE: com.bytedance.sdk.openadsdk.core.b.a{1e83db5 V.E...... ......I. 0,0-0,0}

`

@wuweijian1997
Copy link
Author

我把渲染成功的view 赋值给返回的resultView,但是resultView好像并没有改变,穿山甲的view是异步生成的吗?怎么等view渲染成功之后才返回呢?

@readthecodes
Copy link

正好在搞穿山甲广告SDK集成到RN,Banner广告这块也有点疑惑,楼主能把Banner广告这块也整一下吗?

@readthecodes
Copy link

现在卡在不知道如何将穿山甲的Banner广告做成UI组件,即如何将Banner广告封装成独立的View组件。

@wuweijian1997
Copy link
Author

@wuweijian1997 是的,可以用原生UI组件的方式来集成。
你先把穿山甲的demo在android studio里面跑起来,这个可以方便读懂源码。
你贴的这个应该是信息流广告,对应feed那个例子。把源码里面渲染view的代码移植到你的原生UI组件里面就行了。
RN官方文档:原生UI组件

摩西摩西,大佬在吗?能帮我康康吗?

@readthecodes
Copy link

求人不如求己,我已经封装好 iOS+Android 双平台穿山甲的开屏、激励视频、Banner 广告了

@wuweijian1997
Copy link
Author

求人不如求己,我已经封装好 iOS+Android 双平台穿山甲的开屏、激励视频、Banner 广告了

大佬能康康代码 吗?讲讲思路也行。大佬求开源

@mayunyi
Copy link

mayunyi commented Sep 8, 2024

求人不如求己,我已经封装好 iOS+Android 双平台穿山甲的开屏、激励视频、Banner 广告了

求问为什么渲染banner的不显示,大佬有开源的的代码观摩一下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants