Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16750

Admob reward ads don't work on ios on Expo App

$
0
0

On App.js I have initialized AdMobRewarded as following:

if (Platform.OS === 'ios') {  AdMobRewarded.setAdUnitID('ca-app-pub-xxx/xxx');} else {  AdMobRewarded.setAdUnitID('ca-app-pub-xxx/xxx');}

And here is the class:

export default class App extends React.Component {  state = {    fontsLoaded: false,  };  render() {    const { fontsLoaded } = this.state;    if (!fontsLoaded) {      return (<AppLoading          startAsync={fetchFonts}          onFinish={() => this.setState({ fontsLoaded: true })}        />      );    }    return (<Provider store={store}><AppContainer          ref={navigatorRef => {            NavigationService.setTopLevelNavigator(navigatorRef);          }}        /><CommonComponents /></Provider>    );  }}

Inside the CommonComponents I have put the listener for AdMobRewarded:

useEffect(() => {  AdMobRewarded.addEventListener('rewardedVideoDidRewardUser', () => {    setState({      hintModalVisible: true,      adIsLoading: false,      mainMenuVisible: false,    });  });  return () => {    AdMobRewarded.removeAllListeners();  };}, []);

setState is actually not React setState, it's a redux action I have implemented:

const setStateAction = (obj, sceneName) => {  const type = sceneName ? `${sceneName}_SET_STATE` : 'SET_STATE';  return { ...obj, type };};

Without the rewardedVideoDidRewardUser listener, calling setState does open the Modal and everything is fine.

hintModalVisible is used for Modal isVisible prop, which opens and closes the Modal.

On Android everything works as expected, but there is a strange behavior on iOS. The ad shows for a second and automatically closes, and the Hint Modal doesn't open.

Here is the function that requests and shows the ad. It is present in all screens of the app:

showHint = async () => {  const { setState } = this.props;  try {    setState({      mainMenuVisible: false,    });    await AdMobRewarded.requestAdAsync();    await AdMobRewarded.showAdAsync();  } catch (e) {    setState({      hintModalVisible: true,      mainMenuVisible: false,    });  }};

It's an open source project, so you can the code here


Viewing all articles
Browse latest Browse all 16750

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>