The pangolin advertisement was needed in the recent project. After looking at several plug-ins, I found that they could not meet my needs. All advertisements needed in the project need to be embedded with native View. So I wrote a plug-in to implement the relevant ads. Project warehouse Flutter_unionAD
The official documentation
- Android
- IOS
The integration steps
1, pubspec. Yaml
flutter_unionad: ^1.02.
Copy the code
The introduction of
import 'package:flutter_unionad/flutter_unionad.dart' as FlutterUnionad;
Copy the code
2, the Android
The SDK is integrated into the plugin and no additional configuration is required. You only need to configure androidmanifest.xml in the Android directory
The < manifest... XMLNS: tools ="http://schemas.android.com/tools"... > < application tools: replace ="android:label">
Copy the code
3, the IOS
The SDK has been configured in the plug-in, the rest is configured according to the SDK documentation, because using PlatformView, added in info.plist
<key>io.flutter.embedded_views_preview</key>
<true/>
Copy the code
use
1. Initialize the SDK
await FlutterUnionad.register(
androidAppId: "5098580".// Pangolin AD Android AppID required
iosAppId: "5098580".// Pangolin AD ios AppID required
useTextureView: true.// Use the TextureView control to play the video. The default is SurfaceView. If there is a SurfaceView conflict, use the TextureView option
appName: "unionad_test"./ / appname required
allowShowNotify: true.// Whether to allow the SDK to display notification bar prompts for optional fields
allowShowPageWhenScreenLock: true.// Select whether to support display AD landing page in lock screen scene
debug: true.// The test phase is open, and the problem can be solved through the log. It is too difficult to remove the call when online
supportMultiProcess: true.// Whether multiple processes are supported. True is optional
directDownloadNetworkType: [
FlutterUnionad.NetCode.NETWORK_STATE_2G,
FlutterUnionad.NetCode.NETWORK_STATE_3G,
FlutterUnionad.NetCode.NETWORK_STATE_4G,
FlutterUnionad.NetCode.NETWORK_STATE_WIFI
]); // Allow direct download of the network state set optional // allow direct download of the network state set optional
Copy the code
2. Obtain the SDK version
await FlutterUnionad.getSDKVersion();
Copy the code
3. Request permission
switch (await FlutterUnionad.requestPermissionIfNecessary()) {
/ / in the air
case FlutterUnionad.PermissionCode.notDetermined:
break;
/ / limit
case FlutterUnionad.PermissionCode.restricted:
break;
/ / deny
case FlutterUnionad.PermissionCode.denied:
break;
/ / agree
case FlutterUnionad.PermissionCode.authorized:
break;
}
Copy the code
4. Screen ads
FlutterUnionad.splashAdView(
// Whether to use a personalized template to set the width and height of the widget
mIsExpress: true.// Android open screen AD AD ID mandatory
androidCodeId: "887367774".// Ios open screen AD AD ID mandatory
iosCodeId: "887367774".// Support DeepLink Optional
supportDeepLink: true.// Expected view width dp optional mIsExpress=true Mandatory
expressViewWidth: 750.// Expected view height dp Optional mIsExpress=true Mandatory
expressViewHeight: 800,
callBack: FlutterUnionad.SplashAdCallBack(
onShow: () {
print("Open screen advertising display");
},
onClick: () {
print("Open screen AD click");
Navigator.pop(context);
},
onFail: (error) {
print("Screen ads fail$error");
},
onFinish: () {
print("Open screen AD countdown is over.");
Navigator.pop(context);
},
onSkip: () {
print("Skip the opening AD.");
Navigator.pop(context);
},
onTimeOut: () {
print("Screen time out."); },),),Copy the code
5. Banner ads
FlutterUnionad.bannerAdView(
// Andrrid Banner AD ID Mandatory
androidCodeId: "945410197".// Ios Banner AD ID Mandatory
iosCodeId: "945410197".// Whether to use personalized templates
mIsExpress: true.// Support DeepLink Optional
supportDeepLink: true.// The number of ads requested is greater than 1 and less than 3 must be filled
expressAdNum: 3.// Round cast interval Event 30-120 seconds This parameter is optional
expressTime: 30.// The expected view width dp is mandatory
expressViewWidth: 600.5.// Expected view height dp mandatory
expressViewHeight: 120.5.// The AD event callback is optional
callBack: FlutterUnionad.BannerAdCallBack(
onShow: () {
print("Banner AD loaded");
},
onDislike: (message){
print("Banner wasn't interested$message");
},
onFail: (error){
print("Banner AD failed to load$error");
},
onClick: (){
print("Banner AD click"); })),Copy the code
6. Information flow advertising
FlutterUnionad.nativeAdView(
androidCodeId: "945417699".// Android Info stream AD ID required
iosCodeId: "945417699".// Ios Banner AD ID Mandatory
supportDeepLink: true.// Support DeepLink Optional
expressViewWidth: 375.5.// The expected view width dp is mandatory
expressViewHeight: 275.5.// Expected view height dp mandatory
expressNum: 2,
mIsExpress: true.// The number of ads requested is greater than 1 and less than 3 must be filled
callBack: FlutterUnionad.NativeAdCallBack(
onShow: () {
print("Information flow advertising display");
},
onFail: (error) {
print("Information flow advertising fails$error");
},
onDislike: (message) {
print("Information flow ads are not interested$message");
},
onClick: () {
print("Information stream AD click"); },),),Copy the code
7. Interstitial ads
await FlutterUnionad.interactionAd(
androidCodeId: "945417892".// Andrrid Interstitial AD ID required
iosCodeId: "945417892".// Ios interstitial AD ID Mandatory
supportDeepLink: true.// Support DeepLink Optional
expressViewWidth: 300.0.// The expected view width dp is mandatory
expressViewHeight: 450.0.// Expected view height dp mandatory
);
Copy the code
8. Motivational videos
Preloading motivates video ads
FlutterUnionad.loadRewardVideoAd(
mIsExpress: true.// This parameter is optional
androidCodeId: "945418088".//Android Incentivized video AD ID required
iosCodeId: "945418088".// Ios incentivized video AD ID mandatory
supportDeepLink: true.// Support DeepLink Optional
rewardName: "100 gold".// The name of the reward is optional
rewardAmount: 100.// The number of rewards is optional
userID: "123".// User ID This parameter is optional
orientation: FlutterUnionad.AdOrientation.VERTICAL,
// Select the video direction
mediaExtra: null.// This parameter is optional
);
Copy the code
Display motivational video ads
await FlutterUnionad.showRewardVideoAd();
Copy the code
Listen for motivational video results
FlutterUnionad.FlutterUnionadStream.initAdStream(
// Incentive advertising
rewardAdCallBack: FlutterUnionad.RewardAdCallBack(
onShow: (){
print("Incentivized advertising display");
},
onClick: (){
print("Incentivize AD clicks");
},
onFail: (error){
print("Incentive advertising fails$error");
},
onClose: (){
print("Incentive ads to close.");
},
onSkip: (){
print("Incentivized AD skipping");
},
onVerify: (rewardVerify,rewardAmount,rewardName){
print("Incentive advertising rewards$rewardVerify $rewardAmount $rewardName");
},
onReady: () async{
print("Incentivize AD preloading ready");
// Display incentive ads
await FlutterUnionad.showRewardVideoAd();
},
onUnReady: (){
print("Incentive AD preloading not ready"); },),);Copy the code
Draw video ads
FlutterUnionad.drawFeedAdView(
androidCodeId: "945426252".// Android Draw video AD id required
iosCodeId: "945426252".// Ios Draw video AD id mandatory
supportDeepLink: true.// Support DeepLink Optional
expressViewWidth: 600.5.// The expected view width dp is mandatory
expressViewHeight: 800.5.// Expected view height dp mandatory
callBack: FlutterUnionad.DrawFeedAdCallBack(
onShow: () {
print("Draw AD display");
},
onFail: (error) {
print("Draw AD failed to load$error");
},
onClick: () {
print("Draw AD click");
},
onDislike: (message) {
print("Draw click don't like$message");
},
onVideoPlay: () {
print("Draw video play");
},
onVideoPause: () {
print("Draw video pause");
},
onVideoStop: () {
print("End of Draw video"); })),Copy the code
10. Full-screen video ads
FlutterUnionad.fullScreenVideoAd(
androidCodeId: "945491318".// Android full screen AD ID required
iosCodeId: "945491318".// Ios full screen AD ID Mandatory
supportDeepLink: true.// Support DeepLink Optional
orientation: FlutterUnionad.VideoVERTICAL,// Select the video direction
);
Copy the code
Results the listening
FlutterUnionad.adeventEvent
.receiveBroadcastStream()
.listen((data) {
if(data[FlutterUnionad.adType] == FlutterUnionad.fullVideoAd){
switch(data[FlutterUnionad.fullVideoType]){
case FlutterUnionad.onAdShow:
print("Full screen AD display");
break;
case FlutterUnionad.onAdVideoBarClick:
print("Full screen AD return");
break;
case FlutterUnionad.onAdClose:
print("Full screen ads off.");
break;
case FlutterUnionad.onVideoComplete:
print("Full screen ads continue.");
break;
case FlutterUnionad.onSkippedVideo:
print("Full screen AD skip");
break; }}});Copy the code
11. New template rendering interstitial ads are divided into full screen and interstitial
Preload the new template for rendering interstitial ads
FlutterUnionad.loadFullScreenVideoAdInteraction(
androidCodeId: "946201351".// Android full screen AD ID required
iosCodeId: "946201351".// Ios full screen AD ID Mandatory
supportDeepLink: true.// Support DeepLink Optional
orientation: FlutterUnionad.AdOrientation.VERTICAL, // Select the video direction
);
Copy the code
Display new template rendering interstitial ads
await FlutterUnionad.showFullScreenVideoAdInteraction();
Copy the code
New template rendering interstitial AD result monitor
FlutterUnionad.FlutterUnionadStream.initAdStream(
// New template renders interstitials callback
fullScreenVideoAdInteractionCallBack: FlutterUnionad.FullScreenVideoAdInteractionCallBack(
onShow: () {
print("New template rendering interstitial AD display");
},
onSkip: () {
print("New Template render Interstitial ads skip");
},
onClick: () {
print("New Template render Interstitial AD click");
},
onFinish: () {
print("New template render interstitials are over.");
},
onFail: (error) {
print("New template renders interstitial ads incorrectly$error");
},
onClose: () {
print("New Template render interstitial ads closed");
},
onReady: () async{
print("New template rendering interstitial ready to preload");
// Display the new template rendering screen
await FlutterUnionad.showFullScreenVideoAdInteraction();
},
onUnReady: (){
print("New template rendering interstitial AD not ready for preloading"); },),);Copy the code
The API of the official SDK basically has Flutte invocation scheme. If there is a better scheme or problem, you can ask the Issues to communicate