flutter_umpush 0.0.3

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 62

flutter_umpush

友盟推送、友盟统计的 flutter 插件,使用公司帐号反复测试都是可用的。

这个插件是从我们公司的 cordova 插件分离出来的,集成到 flutter 之后,使用公司的帐号测试可使用,安卓和 ios 都没问题, 在华为手机上测试离线唤醒也没问题。

包括的功能

  1. 友盟统计:已经集成进来了,但是各种友盟的 api 没封装,我们公司之前是 cordova 的项目,只要求统计到设备信息就可以了,没有“埋点的需求”;

  2. 友盟推送:支持小米、华为、魅族的离线唤醒功能,亲测可用。从友盟后台推送的时候,需要勾选“MIUI、EMUI、Flyme 系统设备离线转为系统下发”,填写打开指定页面是:com.github.flutterumpush.UmengOtherPushActivity,100 个放心,本人反复测试过,没问题的。

  3. 由于我们之前是基于 cordova 的项目,不需要 tags,我们只需要根据推送的 url 跳转到指定的界面而已,所有很多功能我没封装。

安卓平台需要注意一下

  1. so 文件只能使用 armeabi-v7a
   ndk {
        moduleName "app"
        abiFilters 'armeabi-v7a'//,'armeabi','arm64-v8a'
   }
  1. 仿照 example/android/app/AndroidManifest.xml,把友盟帐号填写上去;

  2. 必要的时候修改一下安卓 AndroidManifest.xml 的包名和 build.gradle 里面的 aplicationId,

  3. 离线唤醒  需要申请小米、华为、魅族的帐号,请严格参考这个文档进行:https://developer.umeng.com/docs/66632/detail/66744#h1--push-6 有不懂就问他们的在线客服吧。

ios 平台

  1. 工程需要勾中 Remote notification 和 Push Notifications,这样才能支持;
  2. 友盟推送需要在 adhoc 或 distribution 环境下才可以收到推送。我使用 adhoc 发布的,上传到这里https://www.pgyer.com/app/publish,然后下载安装,测试没问题,离线唤醒没问题。

安卓离线唤醒的原理(其他中间商的估计也要这么)

  1. 把信息发给友盟后台,后台再转发给厂商的后台,厂商再把信息推送给手机,由于是厂商的通道,所以绝对能通知到;
  2. 用户点击消息后,由于指定唤醒的界面是 com.github.flutterumpush.UmengOtherPushActivity.java,而不是 MainActivity.java,所以 flutter 和 dart 都没初始化,但是 UmengApplication.java 就初始化了,这是友盟相关 Token 已经生成,然而,由于 flutter 没有初始化,导致无法执行 onToken、onMessage 函数,所以我把 token、message 都缓存到 SharedPreferences。然后根据 URL_SCHEME 唤醒自己;
  3. 这时候才真正实例化 MainActivity.java,也就是初始化 flutter 和 dart,等初始化完毕,在 configure 函数把 SharedPreferences 的东西取出来,执行 onToken、onMessage。

0.0.1

  • TODO: Describe initial release.

example/lib/main.dart

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

void main() => runApp(MyApp());

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

class _MyAppState extends State<MyApp> {
  String _pushData = 'Unknown';
  TextEditingController tokenController = TextEditingController();
  final FlutterUmpush _flutterUmpush = new FlutterUmpush();
  @override
  void initState() {
    super.initState();
    initPushState();
  }

  Future<void> initPushState() async {
    _flutterUmpush.configure(
      onMessage: (String message) async {
        print("main onMessage: $message");
        setState(() {
          _pushData = message;
        });
        return true;
      },
      onLaunch: (String message) async {
        print("main onLaunch: $message");
        setState(() {
          _pushData = message;
        });
        return true;
      },
      onResume: (String message) async {
        print("main onResume: $message");
        setState(() {
          _pushData = message;
        });
        return true;
      },
      onToken: (String token) async {
        print("main onToken: $token");
        setState(() {
          tokenController.text = token;
        });
        return true;
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: <Widget>[
              TextField(
                controller: tokenController,
              ),
              Text('PushData: $_pushData\n')
            ],
          ),
        ),
        floatingActionButton: FloatingActionButton(
          child: Text("GEt"),
          onPressed: () {},
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_umpush: ^0.0.3

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_umpush/flutter_umpush.dart';
  
Version Uploaded Documentation Archive
0.0.3 Sep 25, 2018 Go to the documentation of flutter_umpush 0.0.3 Download flutter_umpush 0.0.3 archive
0.0.2 Sep 25, 2018 Go to the documentation of flutter_umpush 0.0.2 Download flutter_umpush 0.0.2 archive
0.0.1 Sep 25, 2018 Go to the documentation of flutter_umpush 0.0.1 Download flutter_umpush 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
37
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
62
Learn more about scoring.

We analyzed this package on Dec 5, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7
  • Flutter: 1.0.0

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Fix lib/flutter_umpush.dart. (-0.50 points)

Analysis of lib/flutter_umpush.dart reported 1 hint:

line 20 col 18: The value of the field '_platform' isn't used.

Maintenance suggestions

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Package is pre-v0.1 release. (-10 points)

While there is nothing inherently wrong with versions of 0.0.*, it usually means that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
meta ^1.0.4 1.1.6
platform ^2.0.0 2.2.0
Transitive dependencies
collection 1.14.11
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8