Home / IOS Development / Admob reward ads do not work on iOS on the Expo app

Admob reward ads do not work on iOS on the Expo app



On App.js I have initialized AdMobRewarded as follows:

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 (
         this.setState({ fontsLoaded: true })}
        />
      );
    }
    return (
      
         {
            NavigationService.setTopLevelNavigator(navigatorRef);
          }}
        />
        
      
    );
  }
}

Inside CommonComponents I have put the listener to AdMobRewarded:

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

  return () => {
    AdMobRewarded.removeAllListeners();
  };
}, []);

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

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

Without rewardedVideoDidRewardUser listening, calling setState opens Modal and everything is fine.

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

On Android, everything works as expected, but it is a strange behavior on iOS. The ad appears for a second and closes automatically, and Hint Modal does not open.

Here is the feature that requests and displays the ad. It is present in all screenshots 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 is an open source project, so you can code here


Source link