fluocean 0.1.3

  • Readme
  • Changelog
  • Example
  • Installing
  • new58

Getting Started #

fluocean

前言 #

️在使用本插件前请认真,仔细阅读穿山甲官方文档

简介 #

fluocean是一款Flutter插件,集成了字节跳动旗下的广告平台——穿山甲的Android和iOS的SDK,方便开发者直接在Flutter层面调用相关方法。

插件开发环境相关 #

Flutter #

Flutter (Channel beta, 1.18.0-11.1.pre, on Mac OS X 10.14.5, locale zh-Hans-CN)

Dart #

Dart VM version: 2.9.0 on "macos_x64"

Platform #

Xcode - develop for iOS and macOS (Xcode 11.3)
Android Studio (version 4.0)

穿山甲 #

iOS - 2.9.5.6(cocoapods lastest version)
Android - 2.9.5.0

环境配置 #

使用前请确认您以根据穿山甲的官方文档中的步骤进行了相应的依赖添加,权限获取以及参数配置

Android #

穿山甲Android SDK 接入基础配置

iOS

穿山甲iOS SDK 接入基础配置

flocean集成 #

Android #

下载open_ad_sdk.aar。或者从官方SDK下载。 将open_ad_sdk.arr导入工程

iOS #

pod install

穿山甲平台 #

在使用之前必须确认您在穿山甲平台的控制台已经注册了自己app所对应的应用以及对应广告类型的代码位,由于穿山甲包含多种类型的广告和功能请务必确认你在插件中注册的和你在平台注册的一一对应。

开始使用 #

初始化(register) #

调用穿山甲SDK的第一步是对SDK的初始化

import 'package:fluocean/fluocean.dart' as fluocean;

fluocean.OceanResponse r = await fluocean.registerPangolin(
        appId: "appId", // Your appID
        useTextureView: true,
        appName: "appName", // Your appName
        allowShowNotify: true,
        canUseLocation: false,
        allowShowPageWhenScreenLock: true,
        debug: true,
        supportMultiProcess: true);
        
print('success: ${r.isSuccessful}')

参数说明

参数描述默认值
appId在穿山甲平台注册的自己的AppIdnull
useTextureView使用TextureView控件播放视频,默认为SurfaceView,当有SurfaceView冲突的场景,可以使用TextureViewfalse
appName自己的应用名称null
allowShowNotify是否允许sdk展示通知栏提示true
allowShowPageWhenScreenLock是否在锁屏场景支持展示广告落地页true
debug测试阶段打开,可以通过日志排查问题,上线时去除该调用true
supportMultiProcess是否支持多进程false
  • 注意以上参数大部分针对Android端,iOS端由于穿山甲SDK本身的原因并没有过多的参数配置,有用的参数仅为appId,appName。

接入成功debug信息

  • Android
E/TTAdSdk-InitChecker( 7673): ==穿山甲sdk接入,环境为debug,初始化配置检测开始==
E/TTAdSdk-InitChecker( 7673): AndroidManifest.xml中TTFileProvider配置正常
E/TTAdSdk-InitChecker( 7673): AndroidManifest.xml中TTMultiProvider配置正常
E/TTAdSdk-InitChecker( 7673): AndroidManifest.xml中权限配置正常
E/TTAdSdk-InitChecker( 7673): 动态权限没有获取,可能影响转化:android.permission.READ_PHONE_STATE
E/TTAdSdk-InitChecker( 7673): 动态权限没有获取,可能影响转化:android.permission.ACCESS_COARSE_LOCATION
E/TTAdSdk-InitChecker( 7673): 动态权限没有获取,可能影响转化:android.permission.ACCESS_FINE_LOCATION
E/TTAdSdk-InitChecker( 7673): 动态权限没有获取,可能影响转化:android.permission.WRITE_EXTERNAL_STORAGE
E/TTAdSdk-InitChecker( 7673): ==穿山甲sdk初始化配置检测结束==
  • iOS 仅提示穿山甲接入成功

加载开屏广告 #

  • 在初始化成功后执行
fluocean.OceanResponse r =
        await fluocean.loadSplashAd(codeId: '广告位ID', debug: true);
print('loadSplashAd load success: ${r.isSuccessful}');

参数说明

参数描述默认值
codeId在穿山甲平台注册的自己的广告位idnull
debug测试阶段打开,可以通过日志排查问题,上线时去除该调用true

加载激励视频 #

使用前请确认您已在穿山甲平台的控制台建立了你的激励视频广告id。<br/>

fluocean.OceanResponse r = await fluocean.loadRewardAd(
    isHorizontal: true,
    debug: true,
    codeId: "90000000", // 替换为广告位ID
    supportDeepLink: true,
    rewardName: "答题奖励", // 替换为name
    rewardAmount: 1,
    isExpress: true,
    expressViewAcceptedSizeH: 750,
    expressViewAcceptedSizeW: 1334,
    userID: "user",
    mediaExtra: "media_extra");
print('loadRewardAd load success: ${r.isSuccessful}');

参数说明

参数描述默认值
isHorizontal是否横屏false
codeId在穿山甲平台注册的自己的广告位idnull
debug此处debug为true的情况下 我会给你显示整体进程的一个Toast 方便你调试true
supportDeepLink是否横屏false
rewardName奖励的名称null
rewardAmount奖励数量null
isExpress是否进行自渲染(传入后设置激励视频尺寸)true
expressViewAcceptedSizeH渲染视频高度500
expressViewAcceptedSizeW渲染视频宽度500
userID必传参数,表来标识应用侧唯一用户;若非服务器回调模式或不需sdk透传null
mediaExtra用户透传的信息,可不传media_extra

激励视频回调监听 #

在合适的位置注册你的监听,保证用户看完广告时接收到我给你的回调信息,并做下一步处理

fluocean.eventHandler.listen((value) {
  if (value is fluocean.RewardResponse) {
    // 激励视频回调
    if (value.code != 0) {
      print('播放错误: ${value.message}');
      return;
    }
    if (value.message == 'rendered') {
      print('广告开始播放');
      return;
    }
    print(
        'verify: ${value.verify}  amount: ${value.amount} + name: ${value.name}');
  }
});

参数说明

参数描述默认值
verify验证奖励有效性,即用户是否完成观看
name你在穿山甲填写的奖励名称
amount你在穿山甲填写的奖励数量

激励视频的具体使用参见项目目录下Example

版本信息 #

版本更新信息
0.0.1项目初始化
0.1.3集成穿山甲开屏广告与激励广告(支持Android与IOS)

联系方式 #

  • 欢迎小伙伴加入,一起完善。
  • QQ群: 17313538<br/>

0.0.1 #

  • TODO: 初始化项目.

0.1.3 #

  • TODO: 集成穿山甲开屏广告与激励广告(支持Android与IOS)

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'package:fluocean/fluocean.dart' as fluocean;
import 'package:permission_handler/permission_handler.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';

  @override
  void initState() {
    super.initState();
    fluocean.eventHandler.listen((value) {
      if (value is fluocean.RewardResponse) {
        // 激励视频回调
        if (value.code != 0) {
          print('播放错误: ${value.message}');
          return;
        }
        if (value.message == 'rendered') {
          print('广告开始播放');
          return;
        }
        print(
            'verify: ${value.verify}  amount: ${value.amount} + name: ${value.name}');
      }
    });

    initPlatformState();

    initFluocean();
  }

  void initFluocean() async {
    fluocean.OceanResponse r = await fluocean.registerPangolin(
        appId: "appId", // 替换为申请的appID
        useTextureView: true,
        appName: "appName", // 替换为申请的appName
        allowShowNotify: true,
        canUseLocation: false,
        allowShowPageWhenScreenLock: true,
        debug: true,
        supportMultiProcess: true);

    if (r.isSuccessful) {
      // 根据实际项目情况,设置是否直接显示开屏广告
      await loadSplashAd();
    }
  }

  void loadSplashAd() async {
    // codeId 替换为在穿山甲申请的广告位ID
    fluocean.OceanResponse r =
        await fluocean.loadSplashAd(codeId: '8000000', debug: true);
    print('loadSplashAd load success: ${r.isSuccessful}');
  }

  void loadRewardAd() async {
    fluocean.OceanResponse r = await fluocean.loadRewardAd(
        isHorizontal: true,
        debug: true,
        codeId: "90000000", // 替换为广告位ID
        supportDeepLink: true,
        rewardName: "答题奖励", // 替换为name
        rewardAmount: 1,
        isExpress: true,
        expressViewAcceptedSizeH: 750.w,
        expressViewAcceptedSizeW: 1334.h,
        userID: "user",
        mediaExtra: "media_extra");
    print('loadRewardAd load success: ${r.isSuccessful}');
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion = await fluocean.platformVersion;
    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      builder: (context, child) {
        ScreenUtil.init(context,
            width: 750, height: 1334, allowFontScaling: false);
        return child;
      },
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              Text('Running on: $_platformVersion\n'),
              RaisedButton(
                onPressed: loadSplashAd,
                child: Text('开屏广告'),
              ),
              RaisedButton(
                onPressed: loadRewardAd,
                child: Text('激励广告'),
              ),
            ],
          ),
        ),
      ),
    );
  }

  // 请求权限
  void requestPermission() async {
    Map<Permission, PermissionStatus> statuses = await [
      Permission.phone,
      // Permission.location,
      // Permission.storage,
    ].request();
    //校验权限
    if (statuses[Permission.location] != PermissionStatus.granted) {
      print("无位置权限");
    }
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  fluocean: ^0.1.3

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:fluocean/fluocean.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
16
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
58
Learn more about scoring.

We analyzed this package on Jul 6, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because of import path [package:fluocean/fluocean.dart] that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because of import path [package:fluocean/fluocean.dart] that declares support for platforms: android, ios

Package does not support Flutter platform web

Because of import path [package:fluocean/fluocean.dart] that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because of import path [package:fluocean/fluocean.dart] that declares support for platforms: android, ios

Package not compatible with SDK dart

because of import path [fluocean] that is in a package requiring null.

Health issues and suggestions

Document public APIs. (-1 points)

24 out of 24 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Format lib/fluocean.dart.

Run flutter format to format lib/fluocean.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.1
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
flutter_test