Last updated:
0 purchases
mohoflutterplugin
魔盒广告SDK(Flutter版本) #
魔盒广告,支持平台(android,ios),支持广告联盟有(魔盒,穿山甲,优量汇,快手)
使用文档 #
魔盒sdk在使用之前,先需要向我司申请相应的使用权限,以便取得广告ID和Token等信息
Android 相关配置 #
在使用此插件前需要再android平台的//build.gradle 中添加如下代码
allprojects {
repositories {
google()
mavenCentral()
//添加私有库加载地址
maven {
url ="http://app.pomoho.com:9012/nexus/content/repositories/mohosdk"
allowInsecureProtocol = true
}
}
}
copied to clipboard
魔盒最小支持版本为21,请在andorid/app/build.gradle文件中修改支持的最小版本
minSdkVersion 21
copied to clipboard
需要对http的支持,请在android\src\main\AndroidManifest.xml中添加
<application ... android:usesCleartextTraffic="true">
copied to clipboard
ios 相关配置 #
工程plist文件设置,点击右边的information Property List后边的 "+" 展开添加 App Transport Security Settings,先点击左侧展开箭头,再点右侧加号,Allow Arbitrary Loads 选项自动加入,修改值为 YES。 SDK API 已经全部支持HTTPS,但是广告主素材存在非HTTPS情况
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
copied to clipboard
工程plist文件设置,点击右边的information Property List后边的 "+" 展开添加NSMotionUsageDescription,先点击左侧展开箭头,再点右侧加号,NSMotionUsageDescription添加后,设置value值
<key>NSMotionUsageDescription</key>
<string>This app needs to be able to access your motion use</string>
copied to clipboard
从 iOS 14.5 开始,若开发者设置 App Tracking Transparency 向用户申请跟踪授权,在用户授权之前IDFA 将不可用。 如果用户拒绝此请求,应用获取到的 IDFA 将自动清零,可能会导致您的广告收入的降低
要获取 App Tracking Transparency 权限,请更新您的 Info.plist,添加 NSUserTrackingUsageDescription 字段和自定义文案描述
<key>NSUserTrackingUsageDescription</key>
<string>该标识符将用于向您投放个性化广告</string>
copied to clipboard
向用户申请权限时,请调用 requestTrackingAuthorizationWithCompletionHandler:方法
请在ios/Runner/AppDelegate.swift文件中调用下面的方法
swift语言
import AppTrackingTransparency
override func applicationDidBecomeActive(_ application: UIApplication) {
if #available(iOS 14, *) {
ATTrackingManager.requestTrackingAuthorization { status in
}
}
}
copied to clipboard
如果是你是要的是 object-c语言
#import <AppTrackingTransparency/AppTrackingTransparency.h>
- (voi)applicationDidBecomeActive:(UIApplication *)application {
if (@available(iOS 14.0, *)) {
[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
// Tracking authorization completed. Start loading ads here.
}];
}
}
copied to clipboard
SDK初始化 #
使用魔盒sdk之前必须先进行sdk的初始化工作
final mohoPlugin = Mohoflutterplugin();
mohoPlugin.initMohoSDk(AppConfig.appID, AppConfig.appToken);
copied to clipboard
开屏广告 #
import 'package:mohoflutterplugin/event/MohoWidgetListener.dart';
import 'package:mohoflutterplugin/mohoMethodCallHandler.dart';
import 'package:mohoflutterplugin/mohoflutterplugin_platform_interface.dart';
@override
Widget build(BuildContext context) {
var adWidth = MediaQuery.of(context).size.width;
var adHeight = MediaQuery.of(context).size.height * 0.8;
return Scaffold(
appBar: AppBar(title: const Text("开屏广告位")),
body: Column(
children: [
Text(msg),
MohoSplashAdWidget(
appId: AppConfig.appID,
adId: AppConfig.openID,
isFullScreen: false,
adWidth: adWidth,
adHeight: adHeight,
mohoListener: MohoWidgetListener(onLoadSuccess: () {
setState(() {
msg = "广告加载成功";
});
}, onLoadError: (e) {
setState(() {
msg = "广告加载失败$e";
});
}, onAdShow: () {
setState(() {
msg = "$msg \n 广告显示";
});
}, onAdClose: () {
setState(() {
msg = "$msg \n 广告已关闭";
});
}, onAdClicked: () {
setState(() {
msg = "$msg \n 广告被点击";
});
}, onRenderingError: (e) {
setState(() {
msg = "$msg \n 渲染失败$e";
});
}),
)
],
),
);
}
copied to clipboard
banner广告 #
import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';
import 'package:mohoflutterplugin/event/MohoWidgetListener.dart';
import 'package:mohoflutterplugin/mohoMethodCallHandler.dart';
import 'package:mohoflutterplugin/mohoflutterplugin_platform_interface.dart';
@override
Widget build(BuildContext context) {
var adWidth = MediaQuery.of(context).size.width;
var adHeight = adWidth * 0.3;
return Scaffold(
appBar: AppBar(title: const Text("Banner广告位")),
body: Column(
children: [
Text(msg),
MohoBannerAdWidget(
appId: AppConfig.appID,
adId: AppConfig.bannerID,
adWidth: adWidth,
adHeight: adHeight,
mohoListener: MohoWidgetListener(onLoadSuccess: () {
setState(() {
msg = " 加载成功";
});
}, onLoadError: (e) {
setState(() {
msg = "加载失败$e";
});
}, onAdShow: () {
setState(() {
msg = "$msg \n 广告显示";
});
}, onAdClose: () {
setState(() {
msg = "$msg \n 广告已关闭";
});
}, onAdClicked: () {
setState(() {
msg = "$msg \n 广告被点击";
});
}, onRenderingError: (e) {
setState(() {
msg = "$msg \n 渲染失败$e";
});
}),
),
],
),
);
}
copied to clipboard
信息流广告 #
@override
Widget build(BuildContext context) {
var adWidth = MediaQuery.of(context).size.width;
var adHeight = adWidth * 0.8;
return Scaffold(
appBar: AppBar(title: const Text("模板信息流广告位")),
body: Column(
children: [
Text(msg),
MohoTemplateInfomationFlowAdWidget(
appId:AppConfig.appID,
adId: AppConfig.templateAd,
adWidth: adWidth,
adHeight: adHeight,
mohoListener: MohoWidgetListener(onLoadSuccess: () {
setState(() {
msg = "加载成功";
});
}, onLoadError: (e) {
setState(() {
msg = "加载失败$e";
});
}, onAdShow: () {
setState(() {
msg = "$msg \n 广告显示";
});
}, onAdClose: () {
setState(() {
msg = "$msg \n 广告已关闭";
});
}, onAdClicked: () {
setState(() {
msg = "$msg \n 广告被点击";
});
}, onRenderingError: (e) {
setState(() {
msg = "$msg \n 渲染失败$e";
});
}),
),
],
),
);
}
copied to clipboard
draw视频信息流广告 #
@override
Widget build(BuildContext context) {
var adWidth = MediaQuery.of(context).size.width*0.8;
var adHeight = MediaQuery.of(context).size.height*0.8;
return Scaffold(
appBar: AppBar(title: const Text("Draw视频流广告")),
body: Column(
children: [
Text(msg),
MohoDrawAdWidget(
appId: AppConfig.appID,
adId:AppConfig.drawID ,
adWidth: adWidth,
adHeight: adHeight,
mohoListener: MohoWidgetListener(onLoadSuccess: () {
setState(() {
msg = " 加载成功";
});
}, onLoadError: (e) {
setState(() {
msg = " 加载失败$e";
});
}, onAdShow: () {
setState(() {
msg = "$msg \n 广告显示";
});
}, onAdClose: () {
setState(() {
msg = "$msg \n 广告已关闭";
});
}, onAdClicked: () {
setState(() {
msg = "$msg \n 广告被点击";
});
}, onRenderingError: (e) {
setState(() {
msg = "$msg \n 渲染失败$e";
});
}),
),
],
),
);
}
copied to clipboard
插屏广告 #
加载插屏广告
ad = MohoDialogAd(
appID:AppConfig.appID ,
adId: AppConfig.dialogID,
isMute: true, //是否静音,true是静音
isFullScreen: false, //是否是全屏类型
mohoLoadListener: MohoLoadListener(onLoadError: (e) { //加载回调
setState(() {
isShow = false;
msg="插屏广告加载失败$e";
});
}, onLoadSuccess: () {
setState(() {
isShow = true;
msg="插屏广告加载成功!!!";
});
}),
mohoRenderingListener: MohoRenderingListener( //渲染回调
onAdClicked: () {
setState(() {
isShow = false;
msg="广告被点击";
});
},
onAdClose: () {
setState(() {
isShow = false;
msg="广告关闭";
});
},
onRenderingError: (e) {
setState(() {
isShow = false;
msg="插屏渲染失败$e";
});
},
onAdShow: () {
setState(() {
isShow = false;
msg="插屏广告展示";
});
},
));
ad?.load();
copied to clipboard
广告在调用onLoadSuccess成功之后可以进行显示
ad?.show();
copied to clipboard
激励广告 #
ad = MohoRewardAd(
appID: AppConfig.appID,
adId: AppConfig.rewardID,
mohoLoadListener: MohoLoadListener(onLoadError: (e) {
setState(() {
isShow = false;
msg="激励视频广告加载失败$e";
});
}, onLoadSuccess: () {
setState(() {
isShow = true;
msg="激励视频广告加载成功!!!";
});
}),
mohoRenderingListener: MohoRewardRenderingListener(
onAdClicked: () {
setState(() {
isShow = false;
msg="激励视频广告被点击";
});
},
onAdClose: () {
setState(() {
isShow = false;
msg="激励视频广告关闭";
});
},
onRenderingError: (e) {
setState(() {
isShow = false;
msg="激励视频渲染失败$e";
});
},
onAdVideoComplete: (){
setState(() {
isShow = false;
msg="激励视频播放完成";
});
},
onRewardVerify: (){
setState(() {
isShow = false;
msg="激励视频奖励回调";
});
},
onAdShow: () {
setState(() {
isShow = false;
msg="激励视频曝光";
});
},
));
ad?.load();
copied to clipboard
广告在调用onLoadSuccess成功之后可以进行显示
ad?.show();
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.