diff --git a/android/app/capacitor.build.gradle b/android/app/capacitor.build.gradle index 837cd45..64f2c63 100644 --- a/android/app/capacitor.build.gradle +++ b/android/app/capacitor.build.gradle @@ -10,6 +10,7 @@ android { apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle" dependencies { + implementation project(':rdlabo-capacitor-admob') } diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index eb5e4cd..2881d59 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -11,6 +11,10 @@ android:supportsRtl="true" android:theme="@style/AppTheme"> + + >() {{ // Additional plugins you've installed go here // Ex: add(TotallyAwesomePlugin.class); + add(jp.rdlabo.capacitor.plugin.admob.AdMob.class); }}); } } diff --git a/android/capacitor.settings.gradle b/android/capacitor.settings.gradle index 9a5fa87..565e5ce 100644 --- a/android/capacitor.settings.gradle +++ b/android/capacitor.settings.gradle @@ -1,3 +1,6 @@ // DO NOT EDIT THIS FILE! IT IS GENERATED EACH TIME "capacitor update" IS RUN include ':capacitor-android' project(':capacitor-android').projectDir = new File('../node_modules/@capacitor/android/capacitor') + +include ':rdlabo-capacitor-admob' +project(':rdlabo-capacitor-admob').projectDir = new File('../node_modules/@rdlabo/capacitor-admob/android/@rdlabo/capacitor-admob') diff --git a/ios/App/App/AppDelegate.swift b/ios/App/App/AppDelegate.swift index 92c0fc1..6e32fe6 100644 --- a/ios/App/App/AppDelegate.swift +++ b/ios/App/App/AppDelegate.swift @@ -1,5 +1,6 @@ import UIKit import Capacitor +import GoogleMobileAds @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { @@ -9,6 +10,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. + GADMobileAds.sharedInstance().start(completionHandler: nil) return true } diff --git a/ios/App/App/Info.plist b/ios/App/App/Info.plist index 923e6b7..6a299c9 100644 --- a/ios/App/App/Info.plist +++ b/ios/App/App/Info.plist @@ -2,6 +2,8 @@ + GADApplicationIdentifier + ca-app-pub-1053575285730954~8646458891 CFBundleDevelopmentRegion en CFBundleDisplayName diff --git a/ios/App/Podfile b/ios/App/Podfile index c0e5f3f..24aadce 100644 --- a/ios/App/Podfile +++ b/ios/App/Podfile @@ -10,7 +10,7 @@ def capacitor_pods # Automatic Capacitor Pod dependencies, do not delete pod 'Capacitor', :path => '../../node_modules/@capacitor/ios' pod 'CapacitorCordova', :path => '../../node_modules/@capacitor/ios' - + pod 'RdlaboCapacitorAdmob', :path => '../../node_modules/@rdlabo/capacitor-admob' # Do not delete end diff --git a/package.json b/package.json index 5df06b1..ffe67a3 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "@ionic-native/splash-screen": "^5.0.0", "@ionic-native/status-bar": "^5.0.0", "@ionic/angular": "^4.7.1", + "@rdlabo/capacitor-admob": "^0.1.4", "core-js": "^2.5.4", "rxjs": "~6.5.1", "tslib": "^1.9.0", diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 65b00ab..db2ac1d 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -3,6 +3,7 @@ import { Component } from '@angular/core'; import { Platform } from '@ionic/angular'; import { SplashScreen } from '@ionic-native/splash-screen/ngx'; import { StatusBar } from '@ionic-native/status-bar/ngx'; +import { Plugins } from '@capacitor/core'; @Component({ selector: 'app-root', @@ -16,6 +17,9 @@ export class AppComponent { private statusBar: StatusBar ) { this.initializeApp(); + Plugins.AdMob.initialize( + platform.is('ios') ? 'ca-app-pub-1053575285730954~8646458891' : 'ca-app-pub-1053575285730954~3749355430' + ); } initializeApp() { diff --git a/src/app/tab2/tab2.page.html b/src/app/tab2/tab2.page.html index 0eb888a..73daff8 100644 --- a/src/app/tab2/tab2.page.html +++ b/src/app/tab2/tab2.page.html @@ -6,4 +6,9 @@ - + +
+ 広告をだす + 広告を隠す +
+
diff --git a/src/app/tab2/tab2.page.ts b/src/app/tab2/tab2.page.ts index e14cad4..e94afa9 100644 --- a/src/app/tab2/tab2.page.ts +++ b/src/app/tab2/tab2.page.ts @@ -1,4 +1,6 @@ import { Component } from '@angular/core'; +import { Plugins } from '@capacitor/core'; +import { AdOptions, AdSize, AdPosition } from '@rdlabo/capacitor-admob'; @Component({ selector: 'app-tab2', @@ -6,7 +8,25 @@ import { Component } from '@angular/core'; styleUrls: ['tab2.page.scss'] }) export class Tab2Page { - + isAdsense = false; constructor() {} + displayAdMob() { + const options: AdOptions = { + adId: 'ca-app-pub-3940256099942544/6300978111', + adSize: AdSize.BANNER, + position: AdPosition.BOTTOM_CENTER, + margin: '60', + }; + Plugins.AdMob.showBanner(options).then( + success => this.isAdsense = true, + error => this.isAdsense = false + ); + } + + hideAdMob() { + Plugins.AdMob.hideBanner().then( + success => this.isAdsense = false + ); + } } diff --git a/yarn.lock b/yarn.lock index 396c9e8..d4134ca 100644 --- a/yarn.lock +++ b/yarn.lock @@ -329,7 +329,7 @@ which "^1.3.0" xml2js "^0.4.19" -"@capacitor/core@1.1.1": +"@capacitor/core@1.1.1", "@capacitor/core@latest": version "1.1.1" resolved "https://registry.yarnpkg.com/@capacitor/core/-/core-1.1.1.tgz#8e32270d2aa7a843c40b14e4d10c76c62e451d49" integrity sha512-7jnPMy9rGt5VB2QS/1xYEhHspnh2J8i9j0JA6uUtwCUBQs5bmNCqiQ8MYjHTW5NE+1jl2rnX8CU4d8sUT3/esg== @@ -399,6 +399,13 @@ tree-kill "1.2.1" webpack-sources "1.3.0" +"@rdlabo/capacitor-admob@^0.1.4": + version "0.1.4" + resolved "https://registry.yarnpkg.com/@rdlabo/capacitor-admob/-/capacitor-admob-0.1.4.tgz#83ed9da9e3e4a84dd090a2a5c6535659bc793511" + integrity sha512-P8ltIc3l8OUUBvhAWEjqM1zI5/v5YcCnYYsSevGYCLJbBhkpTUYmtoHToCrFmmEhzY3nZ98nKu+gNvOU+KBDRw== + dependencies: + "@capacitor/core" latest + "@schematics/angular@8.1.3": version "8.1.3" resolved "https://registry.yarnpkg.com/@schematics/angular/-/angular-8.1.3.tgz#dc465dae7ef658ac945551e12990676fdac188ec"