「Flutter/admob/firebase admob」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→インストール) |
(→iosの準備) |
||
| 行53: | 行53: | ||
===iosの準備=== | ===iosの準備=== | ||
xcode でios/Runner.xcworkspaceを開きRunner/RunnerへGoogleService-Info.plistファイルをドラッグする。 | xcode でios/Runner.xcworkspaceを開きRunner/RunnerへGoogleService-Info.plistファイルをドラッグする。 | ||
| + | |||
| + | ==サンプル== | ||
| + | 初回起動時 | ||
| + | <pre> | ||
| + | if (Platform.isAndroid) { | ||
| + | FirebaseAdMob.instance.initialize(appId: 'ca-app-pub-067924yyyyyyyyyyy~xxxxxxxxx'); | ||
| + | } else if (Platform.isIOS) { | ||
| + | FirebaseAdMob.instance.initialize(appId: 'ca-app-pub-067924yyyyyyyyyyy~xxxxxxxxx'); | ||
| + | } | ||
| + | </pre> | ||
2019年12月16日 (月) 12:31時点における版
インストール
pubspec.yaml
dependencies: firebase_admob: ^0.9.0+10
準備
android/app/src/main/AndroidManifest.xml
<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="ca-app-pub-xxxxxxx-appid"/>
ios/Runner/Info.Plist
<key>GADApplicationIdentifier</key> <string>ca-app-pub-xxxxxxx-appid</string> <key>io.flutter.embedded_views_preview</key> <true/>
appIdを入れる。
firebase設定を追加
andoridの準備
google-services.jsonをandorid/appの下へ
android/build.gradle
buildscript {
repositories {
google() // Google's Maven repository
}
dependencies {
classpath 'com.google.gms:google-services:3.2.1'
}
}
allprojects {
repositories {
google() // Google's Maven repository
}
}
android/app/build.gradle のファイルの末尾へapply~を追加
dependencies {
}
apply plugin: 'com.google.gms.google-services' // Google Play services Gradle plugin
iosの準備
xcode でios/Runner.xcworkspaceを開きRunner/RunnerへGoogleService-Info.plistファイルをドラッグする。
サンプル
初回起動時
if (Platform.isAndroid) {
FirebaseAdMob.instance.initialize(appId: 'ca-app-pub-067924yyyyyyyyyyy~xxxxxxxxx');
} else if (Platform.isIOS) {
FirebaseAdMob.instance.initialize(appId: 'ca-app-pub-067924yyyyyyyyyyy~xxxxxxxxx');
}
