Code Monkey home page Code Monkey logo

react-native-brayant-ad's Introduction

react-native-brayant-ad

接入穿山甲SDK

后期代办

接入GeoMoreSdk

安装

npm install react-native-brayant-ad

在RN项目的 Project级别的 build.gradle 中添加如下配置 (android/build.gradle)

allprojects {
  repositories {
    google()
    mavenCentral()
    // 添加穿山甲SDK仓库
    maven {
      url 'https://artifact.bytedance.com/repository/pangle'
    }
  }
}

必要配置

在项目入口文件中初始化init, 如果不是全局初始化的就需要在每次调用的时候传入

import { init } from 'react-native-brayant-ad';

useEfect(() => {
  init({
    appid: "xxxx",
    app: "app名称",
    amount: 1000,
    reward: "金币",
    debug: true
  }).then((res) => {})
})

init 方法配置

参数 说明 类型 默认值 是否必填
appid 穿山甲中创建应用的appid string -
app app名称 string 穿山甲媒体APP
uid 有些uid和穿山甲商务有合作的需要 string -
amount 奖励数量 number 1000
reward 奖励名称 string 金币
debug 是否是开发者模式 boolean false

init 成功会返回一个promise

1. 开屏广告

API

dyLoadSplashAd

开屏广告事件类型

interface AD_EVENT_TYPE {
  onAdError: string; // 广告加载失败监听
  onAdClick: string; // 广告被点击监听
  onAdClose: string; // 广告关闭
  onAdSkip: string; // 用户点击跳过广告监听
  onAdShow: string; // 开屏广告开始展示
}

EmuAnim = 'default' | 'none' | 'catalyst' | 'slide' | 'fade';
参数 说明 类型 默认值 是否必填
codeid 广告位id string -
anim 广告进入方式 EmuAnim default

如何使用

这边案列默认全部init初始化后

import { dyLoadSplashAd } from 'react-native-brayant-ad';
import { StyleSheet, Text, View, TouchableOpacity } from 'react-native';

const ScrenPage = () => {
  const onOpenScren = () => {
    const splashAd = dyLoadSplashAd({
      codeid: '889272631',
      anim: 'default',
    });

    splashAd.subscribe('onAdClose', (event) => {
      console.log('广告关闭', event);
    });

    splashAd.subscribe('onAdSkip', (i) => {
      console.log('用户点击跳过监听', i);
    });

    splashAd.subscribe('onAdError', (e) => {
      console.log('开屏加载失败监听', e);
    });

    splashAd.subscribe('onAdClick', (e) => {
      console.log('开屏被用户点击了', e);
    });

    splashAd.subscribe('onAdShow', (e) => {
      console.log('开屏开始展示', e);
    });
  };

  render(){
    return (
      <TouchableOpacity onPress={onOpenScren}>
        <Text style={{ textAlign: 'center' }}> 开屏</Text>
      </TouchableOpacity>
    )
  }

}

2. 激励视频

API

requestPermission

主动看激励视频时,才检查这个权限

无参数 requestPermission()

startRewardVideo 方法参数

开始看激励视频

API

参数 说明 类型 默认值 是否必填
codeid 广告位id string -

激励视频事件类型

export enum AD_EVENT_TYPE {
  onAdError = 'onAdError', // 广告加载失败监听
  onAdLoaded = 'onAdLoaded', // 广告加载成功监听
  onAdClick = 'onAdClick', // 广告被点击监听
  onAdClose = 'onAdClose', // 广告关闭监听
}

如何使用

这边案列默认全部init初始化后

import { requestPermission, startRewardVideo } from 'react-native-brayant-ad';
import { StyleSheet, Text, View, TouchableOpacity } from 'react-native';

const RewardVideoPage = () => {

  const onStartRewardVideo = () => {
    const rewardVideo = startRewardVideo({
      codeid: '956956876',
    });

    rewardVideo.result.then((val: any) => {
      console.log('RewardVideo 回调结果', val);
    });

    rewardVideo.subscribe('onAdLoaded', (event) => {
      console.log('广告加载成功监听', event);
    });

    rewardVideo.subscribe('onAdError', (event) => {
      console.log('广告加载失败监听', event);
    });

    rewardVideo.subscribe('onAdClose', (event) => {
      console.log('广告被关闭监听', event);
    });

    rewardVideo.subscribe('onAdClick', (event) => {
      console.log('广告点击查看详情监听', event);
    });
  };

  render(){
    return (
      <TouchableOpacity onPress={onOpenScren}>
        <Text style={{ textAlign: 'center' }}> 开屏</Text>
      </TouchableOpacity>
    )
  }

}

3. 全屏视频广告

api

startFullScreenVideo 方法参数

参数 说明 类型 默认值 是否必填
codeid 广告位id string -
orientation 竖屏横屏 'HORIZONTAL' | 'VERTICAL' VERTICAL

使用

import { requestPermission, startRewardVideo } from 'react-native-brayant-ad';
import { StyleSheet, Text, View, TouchableOpacity } from 'react-native';

const RewardVideoPage = () => {
  useEffect(() => {
    // step 1: 获取权限
    requestPermission()
  }, []);

  render() {
    return (
      <TouchableOpacity
        style={{
          marginVertical: 20,
          paddingHorizontal: 30,
          paddingVertical: 15,
          backgroundColor: '#F96',
          borderRadius: 50,
        }}
        onPress={() => {
          let fullVideo = startFullScreenVideo({
            codeid: '957781965',
          });
          console.log('FullVideoAd rs:', fullVideo);
          fullVideo.result?.then((val: any) => {
            console.log('FullVideoAd rs then val', val);
          });

          fullVideo.subscribe('onAdLoaded' as any, (event) => {
            console.log('广告加载成功监听', event);
          });

          fullVideo.subscribe('onAdError' as any, (event) => {
            console.log('广告加载失败监听', event);
          });

          fullVideo.subscribe('onAdClose' as any, (event) => {
            console.log('广告被关闭监听', event);
          });

          fullVideo.subscribe('onAdClick' as any, (event) => {
            console.log('广告点击查看详情监听', event);
          });
        }}
      >
        <Text style={{ textAlign: 'center' }}> Start 全屏视频广告</Text>
      </TouchableOpacity>
    )
  }

}

4. Draw广告

api

loadDrawFeedAd 方法参数

参数 说明 类型 默认值 是否必填
codeid 广告位id string -
appid 应用id string -

组件

DrawFeedView

参数 说明 类型 默认值 是否必填
codeid 广告位id string -
appid 应用id string -
visible 是否显示组件中广告 boolean -
appid 应用id string -
style 组件样式 ViewStyle -
onAdError 广告错误事件 Function -
onAdShow 显示广告事件 Function -
onAdClick 点击广告事件 Function -

使用

import { loadDrawFeedAd, DrawFeedView } from 'react-native-brayant-ad';
import { StyleSheet, Text, View, TouchableOpacity } from 'react-native';

const RewardVideoPage = () => {
  useEffect(() => {
    loadDrawFeedAd({
      appid: '****',
      codeid: '****',
    });
  }, []);

  render() {
    return (
      <DrawFeedView
        codeid={'957795405'}
        appid={'5519001'}
        visible={true}
        onAdError={(e: any) => {
          console.log('DrawFeedAd 加载失败', e);
        }}
        onAdShow={(e: any) => {
          console.log('DrawFeedAd 开屏开始展示', e);
        }}
        onAdClick={(e: any) => {
          console.log('onAdClick DrawFeed', e.nativeEvent);
        }}
      />
    )
  }

}

5. 信息流广告

组件

FeedAdView

参数 说明 类型 默认值 是否必填
codeid 广告位id string -
adWidth 广告宽度 number 375
visible 是否显示组件中广告 boolean -
style 组件样式 ViewStyle -
onAdLayout 广告加载成功事件 Function -
onAdClose 广告关闭事件 Function -
onAdClick 广告被用户点击事件 Function -
onAdError 广告加载失败事件 Function -

使用

import { FeedAdView } from 'react-native-brayant-ad';
import { StyleSheet, Text, View, TouchableOpacity } from 'react-native';

const RewardVideoPage = () => {
  useEffect(() => {

  }, []);

  render() {
    return (
      <FeedAdView
        codeid={'****'}
        adWidth={400}
        visible={showFeedView}
        onAdLayout={(data: any) => {
          console.log('Feed 广告加载成功!', data);
        }}
        onAdClose={(data: any) => {
          console.log('Feed 广告关闭!', data);
        }}
        onAdError={(err: any) => {
          console.log('Feed 广告加载失败!', err);
        }}
        onAdClick={(val: any) => {
          console.log('Feed 广告被用户点击!', val);
        }}
      />
    )
  }

}

License

MIT


Made with create-react-native-library

react-native-brayant-ad's People

Stargazers

大狗吱 avatar Boy avatar  avatar Lujia Jin avatar Zolio Marling avatar john river avatar  avatar  avatar MahoneLau avatar codeflying0817 avatar 追风 avatar HuigenYe avatar  avatar TellMeWhy1122 avatar Haoxiang Xu avatar LOL avatar  avatar  avatar  avatar MeiCXi avatar 孙娇女 avatar zhanghao5683934 avatar  avatar Jian avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar ViporMinerProxy avatar wjp avatar ManechoLIU avatar Ma Shiqing avatar F-x avatar  avatar  avatar chiefass avatar  avatar maozi avatar Lex avatar Meta Luo avatar a7 avatar  avatar bingo avatar 杨小灿 avatar  avatar idk avatar zhoumuen avatar  avatar  avatar  avatar feifei avatar jimm avatar HelloSun avatar

Watchers

idk avatar

Forkers

dagouzhi

react-native-brayant-ad's Issues

弹出广告无效

大佬好,我分别调用 onStartRewardVideo, onStartFullVideo,onOpenScren 这三个函数,都是一闪而过,没有出现广告,请问什么原因?

大佬好

大佬好,Gromore 有计划的时间吗?我安卓原生不太会,公司急需接入 GroMore ,谢谢~

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.