在博览会上使用admob时出现错误,提示“ AdmobRewarded.requestAd不是函数”

时间:2019-01-30 06:04:24

标签: react-native admob expo

我正在使用来自expo的admob,同时调用showRewarded方法,其返回如下错误: expo.AdmobRewarded.requestAd(function () { return_expo.AdMobRewarded.showAd();})','_expo.AdMobRewarded.requestAd' is undefined)

我尝试检查方法和对象在那里没有发现任何问题

import { Constants , AdMobRewarded } from 'expo'

class QuoteScreen extends React.Component{
  state = {
            quoteData:[],
            value:20
          }
  incrementCount = () => {

    if(this.state.value<=400){
     this.setState({
        value: this.state.value + 20
            },
             () => {
              this.makeRequest()
            }
              );
          }
     else{
      Alert.alert(
        'Alert',
        'No more Quotes to show',
        [
          {text: 'OK', onPress: () => console.log('OK Pressed')},
        ],

      );
    }
}

  componentDidMount() {
   this.makeRequest()
   AdMobRewarded.setTestDeviceID("EMULATOR");
   // ALWAYS USE TEST ID for Admob ads
   AdMobRewarded.setAdUnitID("ca-app-pub3940256099942544/1712485313");
   AdMobRewarded.addEventListener("rewardedVideoDidRewardUser", () =>
 console.log("did reward user")
   );
    AdMobRewarded.addEventListener("rewardedVideoDidLoad", () =>
 console.log("videodidload")
   );
    AdMobRewarded.addEventListener("rewardedVideoDidFailToLoad", () =>
 console.log("didfailtoload")
    );
   AdMobRewarded.addEventListener("rewardedVideoDidOpen", () =>
 console.log("video didopen")
   );
   AdMobRewarded.addEventListener("rewardedVideoDidClose", () =>{
 console.log("didclose")
 this.incrementCount()
   }
   );
   AdMobRewarded.addEventListener("rewardedVideoWillLeaveApplication", () =>
 console.log("will leave application")
   );

      }
  componentWillUnmount() {
    AdMobRewarded.removeAllListeners();
   }
  showRewarded() {
     // first - load ads and only then - show
    AdMobRewarded.requestAd(() => AdMobRewarded.showAd());
  }

  makeRequest() {

 //calling my api using axios
}
render() {


     return (
       <View style={styles.viewStyles}>
         <View style={styles.statusBarStyle} />
           {this.renderdata()}
          <ImageBackground 
            source={require('../../assets/quotebg.png')}
            style={styles.bgStyle}>

            <FlatList 
              data = {this.state.quoteData}
              renderItem={({item})=> (
                <Card 
                  quotes= {item.quote} 
                />
              )}
              keyExtractor={(item) => item.id}
              ListHeaderComponent={<Header headerText='Books' />}
              onEndReached={this.showRewarded}
              onEndThreshold = {0}
            />


             </ImageBackground>
       </View>
    );
    }
 };

它首先加载20个引号,并在用户向下滚动平面列表时触发onEndReached,该调用调用showRewarded方法。然后触发错误。任何帮助表示赞赏。预先感谢。

0 个答案:

没有答案