友盟推送、友盟统计的 flutter 插件,使用公司帐号反复测试都是可用的。
这个插件是从我们公司的 cordova 插件分离出来的,集成到 flutter 之后,使用公司的帐号测试可使用,安卓和 ios 都没问题, 在华为手机上测试离线唤醒也没问题。
友盟统计:已经集成进来了,但是各种友盟的 api 没封装,我们公司之前是 cordova 的项目,只要求统计到设备信息就可以了,没有“埋点的需求”;
友盟推送:支持小米、华为、魅族的离线唤醒功能,亲测可用。从友盟后台推送的时候,需要勾选“MIUI、EMUI、Flyme 系统设备离线转为系统下发”,填写打开指定页面是:com.github.flutterumpush.UmengOtherPushActivity,100 个放心,本人反复测试过,没问题的。
由于我们之前是基于 cordova 的项目,不需要 tags,我们只需要根据推送的 url 跳转到指定的界面而已,所有很多功能我没封装。
ndk {
moduleName "app"
abiFilters 'armeabi-v7a'//,'armeabi','arm64-v8a'
}
仿照 example/android/app/AndroidManifest.xml,把友盟帐号填写上去;
必要的时候修改一下安卓 AndroidManifest.xml 的包名和 build.gradle 里面的 aplicationId,
离线唤醒 需要申请小米、华为、魅族的帐号,请严格参考这个文档进行:https://developer.umeng.com/docs/66632/detail/66744#h1--push-6 有不懂就问他们的在线客服吧。
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: () {},
),
),
);
}
}
Add this to your package's pubspec.yaml file:
dependencies:
flutter_umpush: ^0.0.3
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.
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 |
|
|
0.0.2 | Sep 25, 2018 |
|
|
0.0.1 | Sep 25, 2018 |
|
|
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
43
|
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]
|
65
|
We analyzed this package on Feb 14, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Detected platforms: Flutter
References Flutter, and has no conflicting libraries.
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.
The package description is too short. (-20 points)
Add more detail to the description
field of pubspec.yaml
. Use 60 to 180 characters to describe the package, what it does, and its target use case.
Package is pre-v0.1 release. (-10 points)
While nothing is inherently wrong with versions of 0.0.*
, it might mean that the author is still experimenting with the general direction of the API.
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 | 1.1.7 |
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 |