Skip to content

Commit

Permalink
📝 升级最新版 SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
BytesZero committed Jan 20, 2025
1 parent d13c839 commit c9f4630
Show file tree
Hide file tree
Showing 12 changed files with 294 additions and 261 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/flutter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11'
java-version: '17'
cache: 'gradle'
# Setup the flutter environment.
- uses: subosito/flutter-action@v2
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 3.1.0
* 🚀 推荐使用【[Gromore Pro](https://flutterads.top/)】 让您的广告收益翻倍
* 新增 `directDownloadNetworkType` 字段,允许直接下载的网络类型
* 升级 Android 和 iOS SDK 到最新版本
* 修复提示【广告 SDK 未 Ready】 的问题
* 迁移升级到 `plugin_platform_interface`

## 3.0.0
* 🚀 推荐使用【[Gromore Pro](https://flutterads.top/)】 让您的广告收益翻倍
* 升级 iOS SDK 到 `v6.2.1.6`
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<img src=https://img.shields.io/github/stars/FlutterAds/flutter_pangle_ads?color=brightgreen>
</a>
<a href="https://flutterads.top/">
<img src="https://img.shields.io/badge/Pro-v3.5.0-success?logo=flutter&logoColor=FFD700"/>
<img src="https://img.shields.io/badge/Pro-v3.8.0-success?logo=flutter&logoColor=FFD700"/>
<a href="https://flutterads.top/">
<img src="https://img.shields.io/badge/Site-FlutterAds-success?logo=webtrees&logoColor=FFD700"/>
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,18 @@ public void initAd(MethodCall call, final MethodChannel.Result result) {
.build();
// 初始化 SDK
TTAdSdk.init(activity.getApplicationContext(), config);
TTAdSdk.start(new TTAdSdk.Callback() {
@Override
public void success() {
result.success(TTAdSdk.isSdkReady());
}

@Override
public void fail(int i, String s) {
result.success(false);
Log.e(TAG, "TTAdSdk init start Error code:"+i+" msg:"+s);
}
});
// 升级提示
Log.w(TAG, "🎉🎉🎉 FlutterAds ==> 初始化完成,推荐使用 GroMore Pro 版本,获得更高的收益:https://flutterads.top/");
}
Expand Down
4 changes: 2 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ description: FlutterAds 穿山甲广告 SDK 插件示例
# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: "none" # Remove this line if you wish to publish to pub.dev
version: 3.0.0+20
version: 3.1.0+20

environment:
sdk: ">=2.12.0 <3.0.0"
sdk: ">=2.12.0 <4.0.0"

dependencies:
flutter:
Expand Down
2 changes: 1 addition & 1 deletion ios/flutter_pangle_ads.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
Pod::Spec.new do |s|
s.name = 'flutter_pangle_ads'
s.version = '3.0.0'
s.version = '3.1.0'
s.summary = 'FlutterAds 一款优质的 Flutter 广告插件(字节跳动、穿山甲)'
s.description = <<-DESC
FlutterAds 致力于构建优质的 Flutter 广告插件
Expand Down
125 changes: 29 additions & 96 deletions lib/flutter_pangle_ads.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import 'dart:async';
import 'dart:io';

import 'package:flutter/services.dart';

import 'flutter_pangle_ads_platform_interface.dart';
import 'event/ad_event_handler.dart';

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

/// 穿山甲广告插件
class FlutterPangleAds {
// 方法通道
static const MethodChannel _methodChannel =
const MethodChannel('flutter_pangle_ads');
// 事件通道
static const EventChannel _eventChannel =
const EventChannel('flutter_pangle_ads_event');
static FlutterPangleAdsPlatform get _platform =>
FlutterPangleAdsPlatform.instance;

/// 请求应用跟踪透明度授权(仅 iOS)
static Future<bool> get requestIDFA async {
if (Platform.isIOS) {
final bool result = await _methodChannel.invokeMethod('requestIDFA');
return result;
}
return true;
}
static Future<bool> get requestIDFA => _platform.requestIDFA();

/// 动态请求相关权限(仅 Android)
static Future<bool> get requestPermissionIfNecessary async {
if (Platform.isAndroid) {
final bool result =
await _methodChannel.invokeMethod('requestPermissionIfNecessary');
return result;
}
return true;
}
static Future<bool> get requestPermissionIfNecessary =>
_platform.requestPermissionIfNecessary();

/// 初始化广告
/// [appId] 应用ID
Expand All @@ -50,37 +32,23 @@ class FlutterPangleAds {
bool supportMultiProcess = false,
bool allowShowNotify = true,
List<int> directDownloadNetworkType = const [],
}) async {
final bool result = await _methodChannel.invokeMethod(
'initAd',
{
'appId': appId,
'useTextureView': useTextureView,
'supportMultiProcess': supportMultiProcess,
'allowShowNotify': allowShowNotify,
'directDownloadNetworkType': directDownloadNetworkType,
},
}) {
return _platform.initAd(
appId,
useTextureView: useTextureView,
supportMultiProcess: supportMultiProcess,
allowShowNotify: allowShowNotify,
directDownloadNetworkType: directDownloadNetworkType,
);
print(
"🎉🎉🎉 FlutterAds ==> 初始化完成,推荐使用 GroMore Pro 版本,获得更高的收益:https://flutterads.top/");
return result;
}

/// 展示开屏广告
/// [posId] 广告位 id
/// [logo] 如果传值则展示底部logo,不传不展示,则全屏展示
/// [timeout] 加载超时时间
static Future<bool> showSplashAd(String posId,
{String? logo, double timeout = 3.5}) async {
final bool result = await _methodChannel.invokeMethod(
'showSplashAd',
{
'posId': posId,
'logo': logo,
'timeout': timeout,
},
);
return result;
{String? logo, double timeout = 3.5}) {
return _platform.showSplashAd(posId, logo: logo, timeout: timeout);
}

/// 展示激励视频广告
Expand All @@ -91,28 +59,15 @@ class FlutterPangleAds {
String posId, {
String? customData,
String? userId,
}) async {
final bool result = await _methodChannel.invokeMethod(
'showRewardVideoAd',
{
'posId': posId,
'customData': customData,
'userId': userId,
},
);
return result;
}) {
return _platform.showRewardVideoAd(posId,
customData: customData, userId: userId);
}

/// 展示全屏视频、新插屏广告
/// [posId] 广告位 id
static Future<bool> showFullScreenVideoAd(String posId) async {
final bool result = await _methodChannel.invokeMethod(
'showFullScreenVideoAd',
{
'posId': posId,
},
);
return result;
static Future<bool> showFullScreenVideoAd(String posId) {
return _platform.showFullScreenVideoAd(posId);
}

/// 加载信息流广告列表
Expand All @@ -121,48 +76,26 @@ class FlutterPangleAds {
/// [height] 高度
/// [count] 获取广告数量,建议 1~3 个
static Future<List<int>> loadFeedAd(String posId,
{int width = 375, int height = 0, int count = 1}) async {
final List<dynamic> result = await _methodChannel.invokeMethod(
'loadFeedAd',
{
'posId': posId,
'width': width,
'height': height,
'count': count,
},
);
return List<int>.from(result);
{int width = 375, int height = 0, int count = 1}) {
return _platform.loadFeedAd(posId,
width: width, height: height, count: count);
}

/// 清除信息流广告列表
/// [list] 信息流广告 id 列表
static Future<bool> clearFeedAd(List<int> list) async {
final bool result = await _methodChannel.invokeMethod(
'clearFeedAd',
{
'list': list,
},
);
return result;
static Future<bool> clearFeedAd(List<int> list) {
return _platform.clearFeedAd(list);
}

///事件回调
///@params onData 事件回调
static Future<void> onEventListener(
OnAdEventListener onAdEventListener) async {
_eventChannel.receiveBroadcastStream().listen((data) {
hanleAdEvent(data, onAdEventListener);
});
static Future<void> onEventListener(OnAdEventListener onAdEventListener) {
return _platform.onEventListener(onAdEventListener);
}

/// 设置个性化推荐
/// @params personalAdsType,不传或传空或传非01值没任何影响,默认不屏蔽, 0屏蔽个性化推荐广告, 1不屏蔽个性化推荐广告
static setUserExtData({required String personalAdsType}) async {
await _methodChannel.invokeMethod(
'setUserExtData',
{
'personalAdsType': personalAdsType,
},
);
static Future<void> setUserExtData({required String personalAdsType}) {
return _platform.setUserExtData(personalAdsType: personalAdsType);
}
}
141 changes: 141 additions & 0 deletions lib/flutter_pangle_ads_method_channel.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import 'dart:async';
import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';

import 'event/ad_event_handler.dart';
import 'flutter_pangle_ads_platform_interface.dart';

/// 基于方法通道的实现
class MethodChannelFlutterPangleAds extends FlutterPangleAdsPlatform {
@visibleForTesting
final methodChannel = const MethodChannel('flutter_pangle_ads');

@visibleForTesting
final eventChannel = const EventChannel('flutter_pangle_ads_event');

@override
Future<bool> requestIDFA() async {
if (Platform.isIOS) {
final bool result = await methodChannel.invokeMethod('requestIDFA');
return result;
}
return true;
}

@override
Future<bool> requestPermissionIfNecessary() async {
if (Platform.isAndroid) {
final bool result =
await methodChannel.invokeMethod('requestPermissionIfNecessary');
return result;
}
return true;
}

@override
Future<bool> initAd(
String appId, {
bool useTextureView = false,
bool supportMultiProcess = false,
bool allowShowNotify = true,
List<int> directDownloadNetworkType = const [],
}) async {
final bool result = await methodChannel.invokeMethod(
'initAd',
{
'appId': appId,
'useTextureView': useTextureView,
'supportMultiProcess': supportMultiProcess,
'allowShowNotify': allowShowNotify,
'directDownloadNetworkType': directDownloadNetworkType,
},
);
print(
"🎉🎉🎉 FlutterAds ==> 初始化完成,推荐使用 GroMore Pro 版本,获得更高的收益:https://flutterads.top/");
return result;
}

@override
Future<bool> showSplashAd(String posId,
{String? logo, double timeout = 3.5}) async {
final bool result = await methodChannel.invokeMethod(
'showSplashAd',
{
'posId': posId,
'logo': logo,
'timeout': timeout,
},
);
return result;
}

@override
Future<bool> showRewardVideoAd(String posId,
{String? customData, String? userId}) async {
final bool result = await methodChannel.invokeMethod(
'showRewardVideoAd',
{
'posId': posId,
'customData': customData,
'userId': userId,
},
);
return result;
}

@override
Future<bool> showFullScreenVideoAd(String posId) async {
final bool result = await methodChannel.invokeMethod(
'showFullScreenVideoAd',
{
'posId': posId,
},
);
return result;
}

@override
Future<List<int>> loadFeedAd(String posId,
{int width = 375, int height = 0, int count = 1}) async {
final List<dynamic> result = await methodChannel.invokeMethod(
'loadFeedAd',
{
'posId': posId,
'width': width,
'height': height,
'count': count,
},
);
return List<int>.from(result);
}

@override
Future<bool> clearFeedAd(List<int> list) async {
final bool result = await methodChannel.invokeMethod(
'clearFeedAd',
{
'list': list,
},
);
return result;
}

@override
Future<void> onEventListener(OnAdEventListener onAdEventListener) async {
eventChannel.receiveBroadcastStream().listen((data) {
hanleAdEvent(data, onAdEventListener);
});
}

@override
Future<void> setUserExtData({required String personalAdsType}) async {
await methodChannel.invokeMethod(
'setUserExtData',
{
'personalAdsType': personalAdsType,
},
);
}
}
Loading

0 comments on commit c9f4630

Please sign in to comment.