Flutter未知功能插件adiscope_flutter_plugin的使用
Flutter未知功能插件adiscope_flutter_plugin的使用
安装插件
首先,在你的 Flutter 项目中安装 adiscope_flutter_plugin
插件。可以通过以下命令进行安装:
flutter pub add adiscope_flutter_plugin
在执行上述命令之前,请确保你在项目的根目录下打开终端并运行该命令。
设置Android
A. 修改AndroidManifest.xml
在 AndroidManifest.xml
文件中添加以下配置:
<application>
<meta-data android:name="adiscope_media_id" android:value="${adiscope_media_id}"/>
<meta-data android:name="adiscope_media_secret" android:value="${adiscope_media_secret}"/>
<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="${adiscope_admob_id}"/>
</application>
B. 配置Gradle
a. 配置Project Gradle
在项目的 build.gradle
文件中添加以下配置:
allprojects {
repositories {
maven { url 'https://repository.adiscope.com/repository/adiscope/' }
maven { url "https://s3.amazonaws.com/smaato-sdk-releases/" }
maven { url "https://verve.jfrog.io/artifactory/verve-gradle-release" }
maven { url "https://artifactory.bidmachine.io/bidmachine" }
maven { url "https://maven.ogury.co" }
maven { url "https://dl-maven-android.mintegral.com/repository/mbridge_android_sdk_oversea" }
maven { url "https://artifact.bytedance.com/repository/pangle" }
maven { url 'https://cboost.jfrog.io/artifactory/chartboost-ads/' }
}
}
b. 配置Module Gradle
在项目的 app/build.gradle
文件中添加以下配置:
android {
defaultConfig {
manifestPlaceholders = [
adiscope_media_id : "媒体ID",
adiscope_media_secret: "媒体密钥",
adiscope_sub_domain : "子域名",
adiscope_admob_id : "Admob应用ID"
]
}
}
dependencies {
implementation 'com.nps.adiscope:adiscopeCore:3.10.3'
implementation 'com.nps.adiscope:adiscopeAndroid:1.2.2'
implementation 'com.nps.adiscope:adapter.chartboost:9.3.1.0'
implementation 'com.nps.adiscope:adapter.max:12.3.1.3'
implementation 'com.nps.adiscope:adapter.admob:22.3.0.5'
implementation "com.nps.adiscope:adapter.pangle:6.1.0.9.0"
implementation 'com.nps.adiscope:adapter.vungle:7.3.2.0'
}
设置iOS
A. 配置Podfile
在 Podfile
文件中添加以下配置:
target 'Runner' do
use_frameworks!
use_modular_headers!
pod 'Adiscope', '3.10.3'
pod 'AdiscopeMediaAdManager', '3.10.3'
pod 'AdiscopeMediaAdMob', '3.10.3'
pod 'AdiscopeMediaChartBoost', '3.10.3'
pod 'AdiscopeMediaPangle', '3.10.3'
pod 'AdiscopeMediaVungle', '3.10.3'
pod 'AdiscopeMediaMax', '3.10.3'
pod 'AdiscopeMediaMaxAdapterAdMob', '3.10.3'
pod 'AdiscopeMediaMaxAdapterAmazon', '3.10.3'
pod 'AdiscopeMediaMaxAdapterBidMachine', '3.10.3'
pod 'AdiscopeMediaMaxAdapterDTExchange', '3.10.3'
pod 'AdiscopeMediaMaxAdapterFan', '3.10.3'
pod 'AdiscopeMediaMaxAdapterInMobi', '3.10.3'
pod 'AdiscopeMediaMaxAdapterMobVista', '3.10.3'
pod 'AdiscopeMediaMaxAdapterMoloco', '3.10.3'
pod 'AdiscopeMediaMaxAdapterOgury', '3.10.3'
pod 'AdiscopeMediaMaxAdapterPangle', '3.10.3'
pod 'AdiscopeMediaMaxAdapterUnityAds', '3.10.3'
pod 'AdiscopeMediaMaxAdapterVungle', '3.10.3'
end
B. 配置Info.plist
在 Info.plist
文件中添加以下配置:
<key>AdiscopeMediaId</key>
<string>媒体ID</string>
<key>AdiscopeMediaSecret</key>
<string>媒体密钥</string>
<key>NSUserTrackingUsageDescription</key>
<string>用户跟踪描述</string>
<key>GADIsAdManagerApp</key>
<true/>
<key>GADApplicationIdentifier</key>
<string>Admob应用ID</string>
<key>AppLovinSdkKey</key>
<string>AppLovin应用ID</string>
使用Adiscope
导入包
在你的 Dart 文件中导入 Adiscope 包:
import 'package:adiscope_flutter_plugin/adiscope_flutter_plugin.dart';
初始化
创建一个 AdiscopeFlutterPlugin 实例,并初始化:
final _adiscopeFlutterPlugin = AdiscopeFlutterPlugin();
Future<void> initialize() async {
bool result = await _adiscopeFlutterPlugin.initialize() ?? false;
if (result) {
// 初始化成功回调
} else {
// 初始化失败
}
}
设置用户信息
设置用户的唯一标识符:
Future<void> setUserId() async {
var userId = ""; // 设置唯一的用户ID以识别用户
bool result = await _adiscopeFlutterPlugin.setUserId(userId) ?? false;
}
展示Offerwall
展示广告墙:
Future<void> showOfferwall() async {
var unitId = ""; // 管理员分配的单元ID
bool result = await _adiscopeFlutterPlugin.showOfferwall(unitId) ?? false;
}
RewardedVideo
加载RewardedVideo广告:
Future<void> rewardedVideoLoad() async {
var unitId = ""; // 管理员分配的单元ID
bool result = await _adiscopeFlutterPlugin.rewardedVideoLoad(unitId) ?? false;
}
检查RewardedVideo广告是否已加载:
Future<void> rewardedVideoIsLoad() async {
var unitId = ""; // 管理员分配的单元ID
bool result = await _adiscopeFlutterPlugin.rewardedVideoIsLoad(unitId) ?? false;
if (result) {
// 广告已加载
} else {
// 广告未加载
}
}
展示RewardedVideo广告:
Future<void> rewardedVideoShow() async {
var unitId = ""; // 管理员分配的单元ID
bool result = await _adiscopeFlutterPlugin.rewardedVideoIsLoad(unitId) ?? false;
if (result) {
bool resultShow = await _adiscopeFlutterPlugin.rewardedVideoShow() ?? false;
if (resultShow) {
// 成功
} else {
// 请求重复
}
} else {
// 广告未加载
}
}
回调
设置 RewardedVideo 的回调:
AdiscopeListener.setupRewardedVideoListener(
onRewarded: (unitId, currencyUnit, amount) {
// 单元ID, 货币单位, 金额
},
);
示例代码
下面是完整的示例代码,展示了如何使用 adiscope_flutter_plugin
插件:
更多关于Flutter未知功能插件adiscope_flutter_plugin的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
1 回复