2.0.0 • Published 4 years ago

@redpill-paris/react-native-ironsource v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

react-native-ironsource

react-native-ironsource is a bridge to use ironsource android and ios SDK .

Part of SDK implemented:

  • Initialisation.
  • Rewarded video.

Install

  yarn add @redpill-paris/react-native-ironsource

Configuration

Android

Add the following to your android/build.gradle file inside repositories section:

  maven {
    url "https://dl.bintray.com/ironsource-mobile/android-sdk"
  }

Then add the following to the dependencies section of your android/ap/build.gradle:

  dependencies {
      implementation 'com.ironsource.sdk:mediationsdk:6.16.2' 
  }

Add the following permissions to your AndroidManifest.xml file inside the manifest tag but outside the tag:

  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Add the following activities inside the tag in your AndroidManifest:

  <activity
    android:name="com.ironsource.sdk.controller.ControllerActivity"
    android:configChanges="orientation|screenSize"
    android:hardwareAccelerated="true"
  />
  <activity
    android:name="com.ironsource.sdk.controller.InterstitialActivity"
    android:configChanges="orientation|screenSize"
    android:hardwareAccelerated="true"
    android:theme="@android:style/Theme.Translucent"
  />
  <activity
    android:name="com.ironsource.sdk.controller.OpenUrlActivity"
    android:configChanges="orientation|screenSize"
    android:hardwareAccelerated="true"
    android:theme="@android:style/Theme.Translucent"
  />

Add the Play Services dependencies into the dependencies block:

  dependencies {
      implementation fileTree(dir: 'libs', include: ['*.jar'])
      implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'
      implementation 'com.google.android.gms:play-services-basement:17.1.1'
  }

You need to add the Network Adapters you want in the podfil of your app.

Exemple:

    implementation 'com.ironsource.adapters:vungleadapter:4.3.0@jar'
    implementation 'com.vungle:publisher-sdk-android:6.5.3'

    implementation 'com.ironsource.adapters:adcolonyadapter:4.3.0@jar'
    implementation 'com.adcolony:sdk:4.1.4'

    implementation 'com.ironsource.adapters:facebookadapter:4.3.14@jar'
    implementation 'com.facebook.android:audience-network-sdk:5.9.0'

Look at the official documentation for more information: https://developers.ironsrc.com/ironsource-mobile/android/mediation-networks-android/

IOS

You need to add the Network Adapters you want in the podfil of your app.

Exemple:

  pod 'IronSourceAppLovinAdapter','> 1'
  pod 'IronSourceVungleAdapter','> 1'
  pod 'IronSourceFacebookAdapter','> 1'
  pod 'IronSourceAdColonyAdapter','> 1'

Look at the official documentation for more information: https://developers.ironsrc.com/ironsource-mobile/ios/mediation-networks-ios/

Methods:

  • Initialisation:

initIronsourceSDK:

  await Ironsource.initIronsourceSDK('a392e26d', 'demoapp', { activateIntegrationHelper: true });

setConsent:

  IronSource.setConsent(true);
  • Rewarded Video:

initializeRewardedVideo

  Ironsource.initializeRewardedVideo();

isRewardedVideoAvailable:

  await Ironsource.isRewardedVideoAvailable();

isRewardedVideoAvailable:

  await Ironsource.isRewardedVideoAvailable();

showRewardedVideo:

  Ironsource.showRewardedVideo('DefaultRewardedVideo');

Listeners

Listeners available:

  • 'ironSourceRewardedVideoAvailable'
  • 'ironSourceRewardedVideoUnavailable'
  • 'ironSourceRewardedVideoDidOpen'
  • 'ironSourceRewardedVideoDidStart'
  • 'ironSourceRewardedVideoClosedByUser'
  • 'ironSourceRewardedVideoClosedByError'
  • 'ironSourceRewardedVideoAdStarted'
  • 'ironSourceRewardedVideoAdEnded'
  • 'ironSourceRewardedVideoAdRewarded'

addEventListener:

    function listenerRewardVideo(resolve, reject) {
      Ironsource.addEventListener('ironSourceRewardedVideoAdRewarded', res => {
        console.log(`Rewarded! ${JSON.stringify(res)}`, 'log');
        resolve();
      });
    }

Exemple:

export default function App() {

  function listenerRewardVideo(resolve, reject) {
    console.log('Setup Listeners reward Video', 'log');
    Ironsource.addEventListener('ironSourceRewardedVideoAdRewarded', res => {
      console.log(`Rewarded! ${JSON.stringify(res)}`, 'log');
      resolve();
    });
    Ironsource.addEventListener('ironSourceRewardedVideoClosedByUser', () => {
      console.log(`Video reward closed by the User`, 'warn');
      Ironsource.removeAllListeners();
      resolve();
    });
    Ironsource.addEventListener('ironSourceRewardedVideoClosedByError', () => {
      console.log(`Video reward closed by an Error`, 'error');
      Ironsource.removeAllListeners();
      reject(new Error('Video closed by an error'));
    });
    console.log('Success Setup Listeners reward Video', 'log');
  }

  return (
    <View style={styles.container}>
      <Button title={'Init'} onPress={async () => {
        console.log('Ironsource from app:', Ironsource);
        await Ironsource.initIronsourceSDK(Platform === 'ios'  ? 'a8de03dd' : 'a392e26d', 'demoapp', { activateIntegrationHelper: true });
      }}/>
      <Button title={'init rewarded'} onPress={() => {
        console.log('init rewarded');
        Ironsource.initializeRewardedVideo();
      }}/>
      <Button title={'call is rewarded'} onPress={async () => {
        console.log('Ironsource is rewarded video available called');
        console.log('Ironsource is rewarded video available ?', await Ironsource.isRewardedVideoAvailable());
      }}/>
      <Button title={'Show'} onPress={() => {
        return new Promise(async (resolve, reject) => {
          listenerRewardVideo(resolve, reject);
          console.log('Ironsource showrewarded video');
          Ironsource.showRewardedVideo('DefaultRewardedVideo');
        });
      }}/>
    </View>
  );
}

Don't forget to take a look at the AppExampleIronsource for more information !