Utku Gökcan
Utku Gökcan

Reputation: 65

Using Unity Ads Cordova Plugin in Capacitor

I would like to use com-artemisoftnian-plugins-unityads3 Cordova plugin inside my Capacitor app. As you know that plugin is not one of Ionic Native plugins.

I added plugin name to capacitor.config.ts.

  cordova:{
    staticPlugins:[
      'com-artemisoftnian-plugins-unityads3'
    ]
  }

Plugin has function exports like UnityAdsInit, ShowVideoAd etc. However, if I use functions by importing it directly I get error Cannot find module “cordova/exec”.

import { UnityAdsInit, ShowVideoAd } from 'com-artemisoftnian-plugins-unityads3/www/UnityAds3';

UnityAdsInit('1234567890', true, true, (res) => {
     console.log(res);
});

I found a way like to use plugin inse window object. But if I use plugin or exported function as window.UnityAdsInit() I get ‘window.UnityAdsInit’ is undefined error.

Actually I am not sure how I should use a Cordova Plugin in Capacitor app. How should I import or use Cordova plugin in Capacitor.

"@capacitor/core": {
      "version": "3.4.0",
}
"@ionic/core": {
      "version": "6.0.7",
}

Upvotes: 1

Views: 724

Answers (1)

NewDevin
NewDevin

Reputation: 31

Sorry I don't know about Capacitor, I'm use Cordova and this plugin com-artemisoftnian-plugins-unityads3 I use this way

cordova.plugins.UnityAds3.UnityAdsInit(gameId, isTest, isDebug, privacyMode, function callback(error, result){            
     if(error){
          console.log(error);                
     }else{
     console.log(result);               
     }
});

More example :

https://github.com/artemisoftnian/com-artemisoftnian-plugins-unityads-public/blob/main/examples/cordova/www/js/index.js

Upvotes: 0

Related Questions