Skip to content

Commit

Permalink
* Android sdk升级4.3.0.1
Browse files Browse the repository at this point in the history
* ios sdk升级4.3.0.2
* 优化广告Widget在原生加载成功后动态调整大小,与原生view保持一致
  • Loading branch information
gstory0404 committed Feb 26, 2022
1 parent d497e68 commit c4630c3
Show file tree
Hide file tree
Showing 15 changed files with 135 additions and 64 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.2.4

* Android sdk升级4.3.0.1
* ios sdk升级4.3.0.2
* 优化广告Widget在原生加载成功后动态调整大小,与原生view保持一致

## 1.2.3

* Android sdk升级4.2.5.2
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 字节跳动穿山甲广告 Flutter版本

<p>
<a href="https://pub.flutter-io.cn/packages/flutter_unionad"><img src=https://img.shields.io/badge/flutter_unionad-v1.2.3-success></a>
<a href="https://pub.flutter-io.cn/packages/flutter_unionad"><img src=https://img.shields.io/badge/flutter_unionad-v1.2.4-success></a>
</p>

<img src="https://github.com/gstory0404/flutter_unionad/blob/master/image/demo.gif" width="30%">
Expand All @@ -15,27 +15,27 @@

## 本地环境
```
[✓] Flutter (Channel stable, 2.10.0, on macOS 12.1 21C52 darwin-x64, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Flutter (Channel stable, 2.10.2, on macOS 12.2.1 21D62 darwin-x64, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc1)
[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] VS Code (version 1.63.2)
[✓] Android Studio (version 2021.1)
[✓] VS Code (version 1.64.2)
[✓] Connected device (4 available)
[✓] HTTP Host Availability
```

## 集成步骤
#### 1、pubspec.yaml
```Dart
flutter_unionad: ^1.2.3
flutter_unionad: ^1.2.4
```
引入
```Dart
import 'package:flutter_unionad/flutter_unionad.dart';
```
#### 2、Android
SDK([4.2.5.2](https://www.csjplatform.com/union/media/union/download/log?id=4))已配置插件中无需额外配置,只需要在android目录中AndroidManifest.xml配置
SDK([4.3.0.1](https://www.csjplatform.com/union/media/union/download/log?id=4))已配置插件中无需额外配置,只需要在android目录中AndroidManifest.xml配置
```Java
<manifest ···
xmlns:tools="http://schemas.android.com/tools"
Expand All @@ -45,7 +45,7 @@ SDK([4.2.5.2](https://www.csjplatform.com/union/media/union/download/log?id=4))
```

#### 3、IOS
SDK([4.2.5.2](https://www.csjplatform.com/union/media/union/download/log?id=16)))已配置插件中,其余根据SDK文档配置,因为使用PlatformView,在Info.plist加入
SDK([4.3.0.2](https://www.csjplatform.com/union/media/union/download/log?id=16)))已配置插件中,其余根据SDK文档配置,因为使用PlatformView,在Info.plist加入
```
<key>io.flutter.embedded_views_preview</key>
<true/>
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ dependencies {
implementation "androidx.appcompat:appcompat:1.3.1"
// implementation 'com.squareup.okhttp3:okhttp:3.12.1'
// implementation 'com.pangle.cn:ads-sdk:+'
implementation 'com.pangle.cn:ads-sdk-pro:4.2.5.2'
implementation 'com.pangle.cn:ads-sdk-pro:4.3.0.1'
// implementation(name: 'open_ad_sdk_4.0.0.1', ext: 'aar')
// implementation(name: 'tools_release', ext: 'aar')
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ internal class BannerExpressAdView(var context: Context, var activity: Activity,
expressViewWidth = width.toFloat()
expressViewHeight = hight.toFloat()
mExpressContainer = FrameLayout(activity)
Log.e("banner广告数量===>",expressAdNum.toString())
Log.e(TAG,expressAdNum.toString())
val mTTAdManager = get()
mTTAdNative = mTTAdManager.createAdNative(context.applicationContext)
channel = MethodChannel(messenger,FlutterunionadViewConfig.bannerAdView+"_"+id)
Expand All @@ -80,14 +80,14 @@ internal class BannerExpressAdView(var context: Context, var activity: Activity,
}

override fun onNativeExpressAdLoad(ads: List<TTNativeExpressAd>) {
if (ads == null || ads.size == 0) {
if (ads == null || ads.isEmpty()) {
return
}
Log.e("banner拉去到广告数量",ads.size.toString())
mTTAd = ads[(0..ads.size - 1).random()]
Log.e(TAG,ads.size.toString())
mTTAd = ads[(ads.indices).random()]
if(null != expressTime && expressTime > 30){
//轮播间隔
mTTAd!!.setSlideIntervalTime(expressTime.toInt() * 1000)
mTTAd!!.setSlideIntervalTime(expressTime * 1000)
}
bindAdListener(mTTAd!!)
startTime = System.currentTimeMillis()
Expand All @@ -98,6 +98,8 @@ internal class BannerExpressAdView(var context: Context, var activity: Activity,


private fun bindAdListener(ad: TTNativeExpressAd) {
var viewWidth = 0.0f
var viewHeight = 0.0f
ad.setExpressInteractionListener(object : ExpressAdInteractionListener {
override fun onAdClicked(view: View, type: Int) {
Log.e(TAG, "广告点击")
Expand All @@ -106,6 +108,8 @@ internal class BannerExpressAdView(var context: Context, var activity: Activity,

override fun onAdShow(view: View, type: Int) {
Log.e(TAG, "广告显示")
var map: MutableMap<String, Any?> = mutableMapOf("width" to viewWidth, "height" to viewHeight)
channel?.invokeMethod("onShow",map)
}

override fun onRenderFail(view: View, msg: String, code: Int) {
Expand All @@ -114,7 +118,7 @@ internal class BannerExpressAdView(var context: Context, var activity: Activity,
}

override fun onRenderSuccess(view: View, width: Float, height: Float) {
Log.e("ExpressView", "render suc:" + (System.currentTimeMillis() - startTime))
Log.e(TAG, "render suc:" + (System.currentTimeMillis() - startTime))
Log.e(TAG, "\nexpressViewWidth=$expressViewWidth " +
"\nexpressViewWidthDP=${UIUtils.px2dip(activity, expressViewWidth)}" +
"\nexpressViewHeight $expressViewHeight" +
Expand All @@ -127,11 +131,10 @@ internal class BannerExpressAdView(var context: Context, var activity: Activity,
mExpressContainer!!.removeAllViews()
// val mExpressContainerParams: FrameLayout.LayoutParams = FrameLayout.LayoutParams(UIUtils.dip2px(activity, width).toInt(), UIUtils.dip2px(activity, height).toInt())
// mExpressContainer!!.layoutParams = mExpressContainerParams
viewWidth = width
viewHeight = height
mExpressContainer!!.addView(view)
channel?.invokeMethod("onShow","")
}


})
//dislike设置
bindDislike(ad, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ internal class DrawFeedExpressAdView(var context: Context, var activity: Activit
})
//是否允许点击暂停视频播放
ad!!.setCanInterruptVideoPlay(true)
var viewWidth = 0.0f
var viewHeight = 0.0f
ad!!.setExpressInteractionListener(object : ExpressAdInteractionListener{
override fun onAdClicked(view: View, type: Int) {
Log.e(TAG, "广告点击")
Expand All @@ -119,7 +121,8 @@ internal class DrawFeedExpressAdView(var context: Context, var activity: Activit

override fun onAdShow(view: View, type: Int) {
Log.e(TAG, "广告显示")
channel?.invokeMethod("onShow","");
var map: MutableMap<String, Any?> = mutableMapOf("width" to viewWidth, "height" to viewHeight)
channel?.invokeMethod("onShow",map);
}

override fun onRenderFail(view: View, msg: String, code: Int) {
Expand All @@ -139,8 +142,10 @@ internal class DrawFeedExpressAdView(var context: Context, var activity: Activit
"\nheightDP= ${UIUtils.dip2px(activity, height)}")
//返回view的宽高 单位 dp
mExpressContainer!!.removeAllViews()
// val mExpressContainerParams: FrameLayout.LayoutParams = FrameLayout.LayoutParams(UIUtils.dip2px(activity, width).toInt(), UIUtils.dip2px(activity, height).toInt())
// mExpressContainer!!.layoutParams = mExpressContainerParams
// val mExpressContainerParams: FrameLayout.LayoutParams = FrameLayout.LayoutParams(UIUtils.dip2px(activity, width).toInt(), UIUtils.dip2px(activity, height).toInt())
// mExpressContainer!!.layoutParams = mExpressContainerParams
viewWidth = width
viewHeight = height
mExpressContainer!!.addView(view)
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ class NativeExpressAdView(var context: Context,var activity: Activity, var messe
}

override fun onNativeExpressAdLoad(ads: List<TTNativeExpressAd>) {
if (ads == null || ads.size == 0) {
if (ads == null || ads.isEmpty()) {
Log.e(TAG, "未拉取到信息流广告")
return
}
//随机获取一条广告显示
mTTAd = ads[(0..ads.size - 1).random()]
mTTAd = ads[(ads.indices).random()]
bindAdListener(mTTAd!!)
mTTAd!!.render() //调用render开始渲染广告
}
Expand Down Expand Up @@ -116,7 +116,8 @@ class NativeExpressAdView(var context: Context,var activity: Activity, var messe
// mExpressContainerParams.gravity = Gravity.CENTER
// mExpressContainer!!.layoutParams = mExpressContainerParams
mExpressContainer!!.addView(view)
channel?.invokeMethod("onShow","")
var map: MutableMap<String, Any?> = mutableMapOf("width" to width, "height" to height)
channel?.invokeMethod("onShow",map)
}
})
//dislike设置
Expand Down
18 changes: 18 additions & 0 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@
9705A1C41CF9048500538489 /* Embed Frameworks */,
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
C93139E4786FB670B9012E8C /* [CP] Copy Pods Resources */,
4D762FC80C06878CECE39CFB /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
Expand Down Expand Up @@ -334,6 +335,23 @@
shellPath = /bin/sh;
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin\n";
};
4D762FC80C06878CECE39CFB /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down
6 changes: 4 additions & 2 deletions ios/Classes/bannerad/BannerAdView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class BannerAdView : NSObject,FlutterPlatformView{
public func view() -> UIView {
return self.container
}

private func loadBannerExpressAd(){
self.removeAllView()
let viewWidth:CGFloat = CGFloat(self.expressViewWidth!)
Expand Down Expand Up @@ -86,7 +86,9 @@ extension BannerAdView: BUNativeExpressBannerViewDelegate {

public func nativeExpressBannerAdViewRenderSuccess(_ bannerAdView: BUNativeExpressBannerView) {
LogUtil.logInstance.printLog(message: "banner渲染成功")
self.channel?.invokeMethod("onShow", arguments: "")
let map : NSDictionary = ["width":bannerAdView.frame.size.width,
"height":bannerAdView.frame.size.height]
self.channel?.invokeMethod("onShow", arguments: map)
}

public func nativeExpressBannerAdViewDidClick(_ bannerAdView: BUNativeExpressBannerView) {
Expand Down
23 changes: 12 additions & 11 deletions ios/Classes/drawfeedad/DrawFeedAdView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,35 +75,36 @@ extension DrawFeedAdView : BUNativeExpressAdViewDelegate{
//view加载成功
public func nativeExpressAdSuccess(toLoad nativeExpressAd: BUNativeExpressAdManager, views: [BUNativeExpressAdView]) {
let view : BUNativeExpressAdView
LogUtil.logInstance.printLog(message: "nativeExpressAdSuccess加载成功")
LogUtil.logInstance.printLog(message: "DrawfeedAd加载成功")
if(views.count > 0){
view = views[0]
view.rootViewController = MyUtils.getVC()
view.render()
self.container.addSubview(view)
self.channel?.invokeMethod("onShow", arguments: "")
let map : NSDictionary = ["width":view.frame.size.width,
"height":view.frame.size.height]
self.channel?.invokeMethod("onShow", arguments: map)
}
}

//加载失败
public func nativeExpressAdFail(toLoad nativeExpressAd: BUNativeExpressAdManager, error: Error?) {
LogUtil.logInstance.printLog(message: "nativeExpressAdFail")
LogUtil.logInstance.printLog(message: "DrawfeedAd Fail")
LogUtil.logInstance.printLog(message: error)
self.channel?.invokeMethod("onFail", arguments: String(error.debugDescription))
}

public func nativeExpressAdViewRenderSuccess(_ nativeExpressAdView: BUNativeExpressAdView) {
LogUtil.logInstance.printLog(message: "nativeExpressAdViewRenderSuccess")
LogUtil.logInstance.printLog(message: "DrawfeedAd RenderSuccess")
}

public func nativeExpressAdView(_ nativeExpressAdView: BUNativeExpressAdView, dislikeWithReason filterWords: [BUDislikeWords]) {
self.disposeView()
LogUtil.logInstance.printLog(message: "nativeExpressAdView")
LogUtil.logInstance.printLog(message: "DrawfeedAd onDislike")
self.channel?.invokeMethod("onDislike", arguments: filterWords[0].name)
}

public func nativeExpressAdView(_ nativeExpressAdView: BUNativeExpressAdView, stateDidChanged playerState: BUPlayerPlayState) {
LogUtil.logInstance.printLog(message: "nativeExpressAdView")
switch playerState {
case BUPlayerPlayState.statePlaying:
self.channel?.invokeMethod("onVideoPlay", arguments: "")
Expand All @@ -121,25 +122,25 @@ extension DrawFeedAdView : BUNativeExpressAdViewDelegate{
}

public func nativeExpressAdViewWillShow(_ nativeExpressAdView: BUNativeExpressAdView) {
LogUtil.logInstance.printLog(message: "nativeExpressAdViewWillShow")
LogUtil.logInstance.printLog(message: "DrawfeedAd WillShow")
}

public func nativeExpressAdViewDidClick(_ nativeExpressAdView: BUNativeExpressAdView) {
LogUtil.logInstance.printLog(message: "nativeExpressAdViewDidClick")
LogUtil.logInstance.printLog(message: "DrawfeedAd DidClick")
self.channel?.invokeMethod("onClick", arguments: nil)
}

public func nativeExpressAdViewWillPresentScreen(_ nativeExpressAdView: BUNativeExpressAdView) {
LogUtil.logInstance.printLog(message: "nativeExpressAdViewWillPresentScreen")
LogUtil.logInstance.printLog(message: "DrawfeedAd WillPresentScreen")
}

public func nativeExpressAdViewRenderFail(_ nativeExpressAdView: BUNativeExpressAdView, error: Error?) {
LogUtil.logInstance.printLog(message: "nativeExpressAdViewRenderFail")
LogUtil.logInstance.printLog(message: "DrawfeedAdv RenderFail")
LogUtil.logInstance.printLog(message: error.debugDescription)
self.channel?.invokeMethod("onFail", arguments: String(error.debugDescription))
}

public func nativeExpressAdViewDidCloseOtherController(_ nativeExpressAdView: BUNativeExpressAdView, interactionType: BUInteractionType) {
LogUtil.logInstance.printLog(message: "nativeExpressAdViewDidCloseOtherController")
LogUtil.logInstance.printLog(message: "DrawfeedAd DidCloseOtherController")
}
}
4 changes: 3 additions & 1 deletion ios/Classes/nativead/NativeAdView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ extension NativeAdView : BUNativeExpressAdViewDelegate{
view.rootViewController = MyUtils.getVC()
view.render()
self.container.addSubview(view)
self.channel?.invokeMethod("onShow", arguments: "")
let map : NSDictionary = ["width":view.frame.size.width,
"height":view.frame.size.height]
self.channel?.invokeMethod("onShow", arguments: map)
}
}

Expand Down
2 changes: 1 addition & 1 deletion ios/flutter_unionad.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ A new flutter plugin project.
s.dependency 'Flutter'
s.platform = :ios, '9.0'
#s.dependency 'Ads-CN','~> 4.2.5.1'
s.dependency 'Ads-CN-Beta','~> 4.2.5.2'
s.dependency 'Ads-CN-Beta','~> 4.3.0.2'
# .framework文件
# s.vendored_frameworks = 'PangleSDK/BUAdSDK.framework','PangleSDK/BUCNAuxiliary.framework','PangleSDK/BUFoundation.framework'
# .a文件
Expand Down
22 changes: 18 additions & 4 deletions lib/bannerad/BannerAdView.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,16 @@ class _BannerAdViewState extends State<BannerAdView> {
//广告是否显示
bool _isShowAd = true;

//宽高
double _width = 0;
double _height = 0;

@override
void initState() {
super.initState();
_isShowAd = true;
_width = widget.expressViewWidth;
_height = widget.expressViewHeight;
}

@override
Expand All @@ -54,8 +60,8 @@ class _BannerAdViewState extends State<BannerAdView> {
}
if (defaultTargetPlatform == TargetPlatform.android) {
return Container(
width: widget.expressViewWidth,
height: widget.expressViewHeight,
width: _width,
height: _height,
child: AndroidView(
viewType: _viewType,
creationParams: {
Expand All @@ -74,8 +80,8 @@ class _BannerAdViewState extends State<BannerAdView> {
);
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
return Container(
width: widget.expressViewWidth,
height: widget.expressViewHeight,
width: _width,
height: _height,
child: UiKitView(
viewType: _viewType,
creationParams: {
Expand Down Expand Up @@ -108,6 +114,14 @@ class _BannerAdViewState extends State<BannerAdView> {
switch (call.method) {
//显示广告
case FlutterUnionadMethod.onShow:
Map map = call.arguments;
if (mounted) {
setState(() {
_isShowAd = true;
_width = (map["width"]).toDouble();
_height = (map["height"]).toDouble();
});
}
widget.callBack?.onShow!();
break;
//广告加载失败
Expand Down
Loading

0 comments on commit c4630c3

Please sign in to comment.