Giter Site home page Giter Site logo

react-native-unityads's Introduction

react-native-unityads

unity ads module

Installation

npm install asdaily-rn-unityads

Usage

import Unityads from 'asdaily-rn-unityads';

  
  //Initialize SDK
  Unityads.initialize(SDK_KEY, 1, (callback) => { //second parameter for test mode, 1 default. 0 for production.
    

    // Attach ad listeners for rewarded ads, and banner ads
    attachAdListeners(); //need to call removeEventListener to remove listeners.
  });
  
  //Attach ad Listeners for rewarded ads, and banner ads, and so on.
  function attachAdListeners() {
    Unityads.addEventListener('onUnityAdsAdFailedToLoad', (errorInfo) => {
      // ad failed to load
      // We recommend retrying with exponentially higher delays up to a maximum delay (in this case 64 seconds)
      setInterstitialRetryAttempt(interstitialRetryAttempt + 1);

      var retryDelay = Math.pow(2, Math.min(6, interstitialRetryAttempt));
      logStatus('Interstitial ad failed to load with code ' + errorInfo + ' - retrying in ' + retryDelay + 's');
    });
    Unityads.addEventListener('onUnityAdsAdLoaded', (adInfo) => {
      logStatus('unity AdLoaded, with ID: ' +adInfo.adUnitId);
    });


    Unityads.addEventListener('onUnityAdsShowComplete', (adInfo) => {
      setUnityAdShowCompleteState(adsShowState.completed);
      logStatus('Ads show completed, with ID: ' +adInfo.adUnitId +" state: "+ adInfo.state);
      if (adInfo.adUnitId == REWARDED_AD_UNIT_ID && adInfo.state == 1) {
        console.log('reward the user');
      }
    });
    Unityads.addEventListener('onUnityAdsShowFailed', (adInfo) => {
      setUnityAdShowCompleteState(adsShowState.failed);
      logStatus('Ads show failed, with ID: '+adInfo.adUnitId +"message: "+ adInfo.message +"error: "+adInfo.error);
      
    });
    Unityads.addEventListener('onUnityAdsShowStart', (adInfo) => {
      setUnityAdShowCompleteState(adsShowState.start);
      logStatus('Ads show started , with ID: '+adInfo.adUnitId);
    });
    Unityads.addEventListener('onUnityAdsShowClick', (adInfo) => {
      setUnityAdShowCompleteState(adsShowState.click);
      logStatus('Ads show clicked, with ID: '+adInfo.adUnitId);
    });
   

    // Banner Ad Listeners
    Unityads.addEventListener('bannerViewDidLoad', (adInfo) => {
      logStatus('Banner ad loaded, with ID: ' +adInfo.adUnitId);
      setIsNativeUIBannerShowing(!isNativeUIBannerShowing);
    });
    Unityads.addEventListener('onBannerViewDidError', (errorInfo) => {
      logStatus('Banner ad failed to load with error code ' + errorInfo.code + ' and message: ' + errorInfo.message);
    });
    Unityads.addEventListener('onBannerViewDidClick', (adInfo) => {
      logStatus('Banner ad clicked');
    });
    Unityads.addEventListener('onBannerViewDidLeaveApplication', (adInfo) => {
      logStatus('Banner ad leave application')
      setIsNativeUIBannerShowing(!isNativeUIBannerShowing);
    });
  }
  
  ios:
  //Modify podfile,add Unity Ads SDK:
  pod 'UnityAds'
  
  For specific usage, please refer to example.
  How To Run example:
  1,$ cd example && npm install
  2,$ cd ios && pod install
  3,$ cd .. && npm run ios or npm run android
  // ...

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

react-native-unityads's People

Stargazers

chenytom avatar  avatar  avatar

Watchers

Terry Jiang avatar

react-native-unityads's Issues

Execution failed for task ':asdaily-rn-unityads:compileReleaseJavaWithJavac'.

System:
OS: macOS 12.5.1
CPU: (8) x64 Apple M1
Memory: 21.49 MB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 14.15.0 - ~/.nvm/versions/node/v14.15.0/bin/node
Yarn: 1.22.19 - ~/.nvm/versions/node/v14.15.0/bin/yarn
npm: 6.14.8 - ~/.nvm/versions/node/v14.15.0/bin/npm
Watchman: 2022.10.31.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: 1.12.0 - /Users/eagle/.rvm/gems/ruby-2.7.6/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 22.1, iOS 16.1, macOS 13.0, tvOS 16.1, watchOS 9.1
Android SDK: Not Found
IDEs:
Android Studio: Not Found
Xcode: 14.1/14B47b - /usr/bin/xcodebuild
Languages:
Java: 11.0.17 - /Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 17.0.2 => 17.0.2
react-native: 0.67.5 => 0.67.5
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found

more error info:

Error while evaluating property 'hasLocalAarDeps' of task ':asdaily-rn-unityads:bundleReleaseAar'.
Direct local .aar file dependencies are not supported when building an AAR. The resulting AAR would be broken because the classes and Android resources from any local .aar file dependencies would not be packaged in the resulting AAR. Previous versions of the Android Gradle Plugin produce broken AARs in this case too (despite not throwing this error). The following direct local .aar file dependencies of the :asdaily-rn-unityads project caused this error: /Users/eagle/Desktop/faceSwing/node_modules/asdaily-rn-unityads/android/libs/unity-ads.aar

Thank you for your lib 👍 👍

I'm spend lot of time to plug unity ads with my react native project. Many lib in npm not working. I think it no one maintenance.

Thank again for this lib

image

onUnityAdsAdFailedToLoad {"error":3,"message":"Placement receives no fill","adUnitId":"Rewarded_iOS"}

System:
OS: macOS 12.5.1
CPU: (8) x64 Apple M1
Memory: 22.18 MB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 14.15.0 - ~/.nvm/versions/node/v14.15.0/bin/node
Yarn: 1.22.19 - ~/.nvm/versions/node/v14.15.0/bin/yarn
npm: 6.14.8 - ~/.nvm/versions/node/v14.15.0/bin/npm
Watchman: 2022.10.31.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: 1.12.0 - /Users/eagle/.rvm/gems/ruby-2.7.6/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 22.1, iOS 16.1, macOS 13.0, tvOS 16.1, watchOS 9.1
Android SDK: Not Found
IDEs:
Android Studio: Not Found
Xcode: 14.1/14B47b - /usr/bin/xcodebuild
Languages:
Java: 11.0.17 - /Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 17.0.2 => 17.0.2
react-native: 0.67.5 => 0.67.5
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found

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.