Skip to content

Commit c9f4630

Browse files
committed
📝 升级最新版 SDK
1 parent d13c839 commit c9f4630

File tree

12 files changed

+294
-261
lines changed

12 files changed

+294
-261
lines changed

.github/workflows/flutter.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- uses: actions/setup-java@v3
1919
with:
2020
distribution: 'temurin'
21-
java-version: '11'
21+
java-version: '17'
2222
cache: 'gradle'
2323
# Setup the flutter environment.
2424
- uses: subosito/flutter-action@v2

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 3.1.0
2+
* 🚀 推荐使用【[Gromore Pro](https://flutterads.top/)】 让您的广告收益翻倍
3+
* 新增 `directDownloadNetworkType` 字段,允许直接下载的网络类型
4+
* 升级 Android 和 iOS SDK 到最新版本
5+
* 修复提示【广告 SDK 未 Ready】 的问题
6+
* 迁移升级到 `plugin_platform_interface`
7+
18
## 3.0.0
29
* 🚀 推荐使用【[Gromore Pro](https://flutterads.top/)】 让您的广告收益翻倍
310
* 升级 iOS SDK 到 `v6.2.1.6`

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<img src=https://img.shields.io/github/stars/FlutterAds/flutter_pangle_ads?color=brightgreen>
1313
</a>
1414
<a href="https://flutterads.top/">
15-
<img src="https://img.shields.io/badge/Pro-v3.5.0-success?logo=flutter&logoColor=FFD700"/>
15+
<img src="https://img.shields.io/badge/Pro-v3.8.0-success?logo=flutter&logoColor=FFD700"/>
1616
<a href="https://flutterads.top/">
1717
<img src="https://img.shields.io/badge/Site-FlutterAds-success?logo=webtrees&logoColor=FFD700"/>
1818
</a>

android/src/main/java/com/zero/flutter_pangle_ads/PluginDelegate.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,18 @@ public void initAd(MethodCall call, final MethodChannel.Result result) {
186186
.build();
187187
// 初始化 SDK
188188
TTAdSdk.init(activity.getApplicationContext(), config);
189+
TTAdSdk.start(new TTAdSdk.Callback() {
190+
@Override
191+
public void success() {
192+
result.success(TTAdSdk.isSdkReady());
193+
}
194+
195+
@Override
196+
public void fail(int i, String s) {
197+
result.success(false);
198+
Log.e(TAG, "TTAdSdk init start Error code:"+i+" msg:"+s);
199+
}
200+
});
189201
// 升级提示
190202
Log.w(TAG, "🎉🎉🎉 FlutterAds ==> 初始化完成,推荐使用 GroMore Pro 版本,获得更高的收益:https://flutterads.top/");
191203
}

example/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ description: FlutterAds 穿山甲广告 SDK 插件示例
44
# The following line prevents the package from being accidentally published to
55
# pub.dev using `pub publish`. This is preferred for private packages.
66
publish_to: "none" # Remove this line if you wish to publish to pub.dev
7-
version: 3.0.0+20
7+
version: 3.1.0+20
88

99
environment:
10-
sdk: ">=2.12.0 <3.0.0"
10+
sdk: ">=2.12.0 <4.0.0"
1111

1212
dependencies:
1313
flutter:

ios/flutter_pangle_ads.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
Pod::Spec.new do |s|
66
s.name = 'flutter_pangle_ads'
7-
s.version = '3.0.0'
7+
s.version = '3.1.0'
88
s.summary = 'FlutterAds 一款优质的 Flutter 广告插件(字节跳动、穿山甲)'
99
s.description = <<-DESC
1010
FlutterAds 致力于构建优质的 Flutter 广告插件

lib/flutter_pangle_ads.dart

Lines changed: 29 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import 'dart:async';
2-
import 'dart:io';
3-
4-
import 'package:flutter/services.dart';
52

3+
import 'flutter_pangle_ads_platform_interface.dart';
64
import 'event/ad_event_handler.dart';
75

86
export 'event/ad_event_handler.dart';
@@ -12,31 +10,15 @@ export 'view/ad_feed_widget.dart';
1210

1311
/// 穿山甲广告插件
1412
class FlutterPangleAds {
15-
// 方法通道
16-
static const MethodChannel _methodChannel =
17-
const MethodChannel('flutter_pangle_ads');
18-
// 事件通道
19-
static const EventChannel _eventChannel =
20-
const EventChannel('flutter_pangle_ads_event');
13+
static FlutterPangleAdsPlatform get _platform =>
14+
FlutterPangleAdsPlatform.instance;
2115

2216
/// 请求应用跟踪透明度授权(仅 iOS)
23-
static Future<bool> get requestIDFA async {
24-
if (Platform.isIOS) {
25-
final bool result = await _methodChannel.invokeMethod('requestIDFA');
26-
return result;
27-
}
28-
return true;
29-
}
17+
static Future<bool> get requestIDFA => _platform.requestIDFA();
3018

3119
/// 动态请求相关权限(仅 Android)
32-
static Future<bool> get requestPermissionIfNecessary async {
33-
if (Platform.isAndroid) {
34-
final bool result =
35-
await _methodChannel.invokeMethod('requestPermissionIfNecessary');
36-
return result;
37-
}
38-
return true;
39-
}
20+
static Future<bool> get requestPermissionIfNecessary =>
21+
_platform.requestPermissionIfNecessary();
4022

4123
/// 初始化广告
4224
/// [appId] 应用ID
@@ -50,37 +32,23 @@ class FlutterPangleAds {
5032
bool supportMultiProcess = false,
5133
bool allowShowNotify = true,
5234
List<int> directDownloadNetworkType = const [],
53-
}) async {
54-
final bool result = await _methodChannel.invokeMethod(
55-
'initAd',
56-
{
57-
'appId': appId,
58-
'useTextureView': useTextureView,
59-
'supportMultiProcess': supportMultiProcess,
60-
'allowShowNotify': allowShowNotify,
61-
'directDownloadNetworkType': directDownloadNetworkType,
62-
},
35+
}) {
36+
return _platform.initAd(
37+
appId,
38+
useTextureView: useTextureView,
39+
supportMultiProcess: supportMultiProcess,
40+
allowShowNotify: allowShowNotify,
41+
directDownloadNetworkType: directDownloadNetworkType,
6342
);
64-
print(
65-
"🎉🎉🎉 FlutterAds ==> 初始化完成,推荐使用 GroMore Pro 版本,获得更高的收益:https://flutterads.top/");
66-
return result;
6743
}
6844

6945
/// 展示开屏广告
7046
/// [posId] 广告位 id
7147
/// [logo] 如果传值则展示底部logo,不传不展示,则全屏展示
7248
/// [timeout] 加载超时时间
7349
static Future<bool> showSplashAd(String posId,
74-
{String? logo, double timeout = 3.5}) async {
75-
final bool result = await _methodChannel.invokeMethod(
76-
'showSplashAd',
77-
{
78-
'posId': posId,
79-
'logo': logo,
80-
'timeout': timeout,
81-
},
82-
);
83-
return result;
50+
{String? logo, double timeout = 3.5}) {
51+
return _platform.showSplashAd(posId, logo: logo, timeout: timeout);
8452
}
8553

8654
/// 展示激励视频广告
@@ -91,28 +59,15 @@ class FlutterPangleAds {
9159
String posId, {
9260
String? customData,
9361
String? userId,
94-
}) async {
95-
final bool result = await _methodChannel.invokeMethod(
96-
'showRewardVideoAd',
97-
{
98-
'posId': posId,
99-
'customData': customData,
100-
'userId': userId,
101-
},
102-
);
103-
return result;
62+
}) {
63+
return _platform.showRewardVideoAd(posId,
64+
customData: customData, userId: userId);
10465
}
10566

10667
/// 展示全屏视频、新插屏广告
10768
/// [posId] 广告位 id
108-
static Future<bool> showFullScreenVideoAd(String posId) async {
109-
final bool result = await _methodChannel.invokeMethod(
110-
'showFullScreenVideoAd',
111-
{
112-
'posId': posId,
113-
},
114-
);
115-
return result;
69+
static Future<bool> showFullScreenVideoAd(String posId) {
70+
return _platform.showFullScreenVideoAd(posId);
11671
}
11772

11873
/// 加载信息流广告列表
@@ -121,48 +76,26 @@ class FlutterPangleAds {
12176
/// [height] 高度
12277
/// [count] 获取广告数量,建议 1~3 个
12378
static Future<List<int>> loadFeedAd(String posId,
124-
{int width = 375, int height = 0, int count = 1}) async {
125-
final List<dynamic> result = await _methodChannel.invokeMethod(
126-
'loadFeedAd',
127-
{
128-
'posId': posId,
129-
'width': width,
130-
'height': height,
131-
'count': count,
132-
},
133-
);
134-
return List<int>.from(result);
79+
{int width = 375, int height = 0, int count = 1}) {
80+
return _platform.loadFeedAd(posId,
81+
width: width, height: height, count: count);
13582
}
13683

13784
/// 清除信息流广告列表
13885
/// [list] 信息流广告 id 列表
139-
static Future<bool> clearFeedAd(List<int> list) async {
140-
final bool result = await _methodChannel.invokeMethod(
141-
'clearFeedAd',
142-
{
143-
'list': list,
144-
},
145-
);
146-
return result;
86+
static Future<bool> clearFeedAd(List<int> list) {
87+
return _platform.clearFeedAd(list);
14788
}
14889

14990
///事件回调
15091
///@params onData 事件回调
151-
static Future<void> onEventListener(
152-
OnAdEventListener onAdEventListener) async {
153-
_eventChannel.receiveBroadcastStream().listen((data) {
154-
hanleAdEvent(data, onAdEventListener);
155-
});
92+
static Future<void> onEventListener(OnAdEventListener onAdEventListener) {
93+
return _platform.onEventListener(onAdEventListener);
15694
}
15795

15896
/// 设置个性化推荐
15997
/// @params personalAdsType,不传或传空或传非01值没任何影响,默认不屏蔽, 0屏蔽个性化推荐广告, 1不屏蔽个性化推荐广告
160-
static setUserExtData({required String personalAdsType}) async {
161-
await _methodChannel.invokeMethod(
162-
'setUserExtData',
163-
{
164-
'personalAdsType': personalAdsType,
165-
},
166-
);
98+
static Future<void> setUserExtData({required String personalAdsType}) {
99+
return _platform.setUserExtData(personalAdsType: personalAdsType);
167100
}
168101
}
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
import 'dart:async';
2+
import 'dart:io';
3+
4+
import 'package:flutter/foundation.dart';
5+
import 'package:flutter/services.dart';
6+
7+
import 'event/ad_event_handler.dart';
8+
import 'flutter_pangle_ads_platform_interface.dart';
9+
10+
/// 基于方法通道的实现
11+
class MethodChannelFlutterPangleAds extends FlutterPangleAdsPlatform {
12+
@visibleForTesting
13+
final methodChannel = const MethodChannel('flutter_pangle_ads');
14+
15+
@visibleForTesting
16+
final eventChannel = const EventChannel('flutter_pangle_ads_event');
17+
18+
@override
19+
Future<bool> requestIDFA() async {
20+
if (Platform.isIOS) {
21+
final bool result = await methodChannel.invokeMethod('requestIDFA');
22+
return result;
23+
}
24+
return true;
25+
}
26+
27+
@override
28+
Future<bool> requestPermissionIfNecessary() async {
29+
if (Platform.isAndroid) {
30+
final bool result =
31+
await methodChannel.invokeMethod('requestPermissionIfNecessary');
32+
return result;
33+
}
34+
return true;
35+
}
36+
37+
@override
38+
Future<bool> initAd(
39+
String appId, {
40+
bool useTextureView = false,
41+
bool supportMultiProcess = false,
42+
bool allowShowNotify = true,
43+
List<int> directDownloadNetworkType = const [],
44+
}) async {
45+
final bool result = await methodChannel.invokeMethod(
46+
'initAd',
47+
{
48+
'appId': appId,
49+
'useTextureView': useTextureView,
50+
'supportMultiProcess': supportMultiProcess,
51+
'allowShowNotify': allowShowNotify,
52+
'directDownloadNetworkType': directDownloadNetworkType,
53+
},
54+
);
55+
print(
56+
"🎉🎉🎉 FlutterAds ==> 初始化完成,推荐使用 GroMore Pro 版本,获得更高的收益:https://flutterads.top/");
57+
return result;
58+
}
59+
60+
@override
61+
Future<bool> showSplashAd(String posId,
62+
{String? logo, double timeout = 3.5}) async {
63+
final bool result = await methodChannel.invokeMethod(
64+
'showSplashAd',
65+
{
66+
'posId': posId,
67+
'logo': logo,
68+
'timeout': timeout,
69+
},
70+
);
71+
return result;
72+
}
73+
74+
@override
75+
Future<bool> showRewardVideoAd(String posId,
76+
{String? customData, String? userId}) async {
77+
final bool result = await methodChannel.invokeMethod(
78+
'showRewardVideoAd',
79+
{
80+
'posId': posId,
81+
'customData': customData,
82+
'userId': userId,
83+
},
84+
);
85+
return result;
86+
}
87+
88+
@override
89+
Future<bool> showFullScreenVideoAd(String posId) async {
90+
final bool result = await methodChannel.invokeMethod(
91+
'showFullScreenVideoAd',
92+
{
93+
'posId': posId,
94+
},
95+
);
96+
return result;
97+
}
98+
99+
@override
100+
Future<List<int>> loadFeedAd(String posId,
101+
{int width = 375, int height = 0, int count = 1}) async {
102+
final List<dynamic> result = await methodChannel.invokeMethod(
103+
'loadFeedAd',
104+
{
105+
'posId': posId,
106+
'width': width,
107+
'height': height,
108+
'count': count,
109+
},
110+
);
111+
return List<int>.from(result);
112+
}
113+
114+
@override
115+
Future<bool> clearFeedAd(List<int> list) async {
116+
final bool result = await methodChannel.invokeMethod(
117+
'clearFeedAd',
118+
{
119+
'list': list,
120+
},
121+
);
122+
return result;
123+
}
124+
125+
@override
126+
Future<void> onEventListener(OnAdEventListener onAdEventListener) async {
127+
eventChannel.receiveBroadcastStream().listen((data) {
128+
hanleAdEvent(data, onAdEventListener);
129+
});
130+
}
131+
132+
@override
133+
Future<void> setUserExtData({required String personalAdsType}) async {
134+
await methodChannel.invokeMethod(
135+
'setUserExtData',
136+
{
137+
'personalAdsType': personalAdsType,
138+
},
139+
);
140+
}
141+
}

0 commit comments

Comments
 (0)