fake_push 0.5.4

  • Readme
  • Changelog
  • Example
  • Installing
  • 73

fake_push #

Build Status Codecov GitHub Tag Pub Package License

flutter版腾讯(信鸽)推送SDK

fake 系列 libraries #

dart/flutter 私服 #

docs #

verify #

  • [x] 华为通道(Android)
  • [x] 小米通道(Android)
  • [x] 信鸽通道(Android)
  • [x] 信鸽通道(iOS)

android #

# 混淆已打入 Library,随 Library 引用,自动添加到 apk 打包混淆
...
android {
    ...
    defaultConfig {
        ...
        manifestPlaceholders = [
                XG_ACCESS_ID    : '${信鸽ACCESSID}',
                XG_ACCESS_KEY   : '${信鸽ACCESSKEY}',
                XG_ACCESS_SCHEME: '${信鸽统一打开APP行为SCHEME}',// 非官方参数,可自定义(例如:fake_push),统一打开方式为 intent
                HW_APPID        : '${华为的APPID}',
                XIAOMI_APPID    : '${小米的APPID}',
                XIAOMI_APPKEY   : '${小米的APPKEY}',
                PACKAGE_NAME    : "${applicationId}",// 小米通道
        ]
        ...
    }
    ...
}

通知打开应用 -> 使用Intent来跳转指定页面

例如:
fake_push://v7lin.github.io/notify_detail
fake_push://v7lin.github.io/notify_detail?param1=aa&param2=bb

ios #

# Capabilities
Background Modes -> Remote notifications
Push Notifications
# info 添加字段 XG_ACCESS_ID、XG_ACCESS_KEY
<key>XG_ACCESS_ID</key>
<string>${信鸽ACCESSID}</string>
<key>XG_ACCESS_KEY</key>
<string>${信鸽ACCESSKEY}</string>

flutter #

  • snapshot
dependencies:
  fake_push:
    git:
      url: https://github.com/v7lin/fake_push.git
  • release
dependencies:
  fake_push: ^${latestTag}

Demo #

Demo

Getting Started #

This project is a starting point for a Flutter plug-in package, a specialized package that includes platform-specific implementation code for Android and/or iOS.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

0.5.4 - 2020.03.07 #

  • 华为证书

0.5.3 - 2019.12.02 #

  • 优化混淆,兼容R8

0.5.2 - 2019.11.25 #

  • 升级iOS SDK,兼容iOS 13

0.5.1 - 2019.7.12 #

  • 简化

0.5.0 - 2019.7.6 #

  • 优化Android厂商推送
  • 优化iOS推送
  • 统一API

0.4.1 - 2019.6.19 #

  • 升级Android SDK
  • 获取DeviceToken

0.4.0 - 2019.5.24 #

  • 优化
  • 自动化发布

0.3.0+2 - 2019.5.13 #

  • fix issues#4

0.3.0+1 - 2019.5.7 #

  • 兼容 AndroidX,去除 android support library 依赖

0.3.0 - 2019.4.28 #

  • 优化

0.2.0 - 2019.4.22 #

  • android/ios xinge push

0.1.0 - 2019.3.26 #

  • android/ios baidu push

example/lib/main.dart

import 'dart:async';
import 'dart:io';

import 'package:fake_push/fake_push.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:shared_preferences/shared_preferences.dart';

void main() {
  runZoned(() {
    runApp(MyApp());
  }, onError: (Object error, StackTrace stack) {
    print(error);
    print(stack);
  });

  if (Platform.isAndroid) {
    SystemUiOverlayStyle systemUiOverlayStyle =
        const SystemUiOverlayStyle(statusBarColor: Colors.transparent);
    SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
  }
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Home(),
    );
  }
}

class Home extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _HomeState();
  }
}

class _HomeState extends State<Home> {
  Push _push = Push();

  StreamSubscription<String> _receiveDeviceToken;
  StreamSubscription<Message> _receiveMessage;
  StreamSubscription<Message> _receiveNotification;
  StreamSubscription<String> _launchNotification;
  StreamSubscription<String> _resumeNotification;

  @override
  void initState() {
    super.initState();
    _receiveDeviceToken =
        _push.receiveDeviceToken().listen(_handleReceiveDeviceToken);
    _receiveMessage = _push.receiveMessage().listen(_handleReceiveMessage);
    _receiveNotification =
        _push.receiveNotification().listen(_handleReceiveNotification);
    _launchNotification =
        _push.launchNotification().listen(_handleLaunchNotification);
    _resumeNotification =
        _push.resumeNotification().listen(_handleResumeNotification);

    _push.startWork(enableDebug: !_isReleaseMode());
    // 第二次打开应用再调用
    SharedPreferences.getInstance().then((SharedPreferences sharedPref) {
      if (sharedPref.getBool('firstStart') ?? true) {
        sharedPref.setBool('firstStart', false);
      } else {
        _push.areNotificationsEnabled().then((bool isEnabled) {
          if (!isEnabled) {
            showCupertinoDialog(
              context: context,
              builder: (BuildContext context) {
                return CupertinoAlertDialog(
                  title: const Text('提示'),
                  content: const Text('开启通知权限可收到更多优质内容'),
                  actions: <Widget>[
                    CupertinoDialogAction(
                      child: const Text('取消'),
                      onPressed: () {
                        Navigator.of(context).pop();
                      },
                    ),
                    CupertinoDialogAction(
                      child: const Text('设置'),
                      onPressed: () {
                        _push.openNotificationsSettings();
                        Navigator.of(context).pop();
                      },
                    ),
                  ],
                );
              },
            );
          }
        });
      }
    });
  }

  void _handleReceiveDeviceToken(String deviceToken) async {
    print('receiveDeviceToken: $deviceToken - ${await _push.getDeviceToken()}');
    _showTips('receiveDeviceToken', deviceToken);
  }

  void _handleReceiveMessage(Message message) {
    print(
        'receiveMessage: ${message.title} - ${message.content} - ${message.customContent}');
    _showTips('receiveMessage',
        '${message.title} - ${message.content} - ${message.customContent}');
  }

  void _handleReceiveNotification(Message notification) {
    print(
        'receiveNotification: ${notification.title} - ${notification.content} - ${notification.customContent}');
    _showTips('receiveNotification',
        '${notification.title} - ${notification.content} - ${notification.customContent}');
  }

  void _handleLaunchNotification(String customContent) {
    print('launchNotification: $customContent');
    _showTips('launchNotification', customContent);
  }

  void _handleResumeNotification(String customContent) {
    print('resumeNotification: $customContent');
    _showTips('resumeNotification', customContent);
  }

  void _showTips(String title, String content) {
    showCupertinoDialog(
      context: context,
      builder: (BuildContext context) {
        return CupertinoAlertDialog(
          title: Text(title),
          content: Text(content),
          actions: <Widget>[
            CupertinoDialogAction(
              child: const Text('朕知道了~'),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
          ],
        );
      },
    );
  }

  bool _isReleaseMode() {
    return const bool.fromEnvironment('dart.vm.product');
  }

  @override
  void dispose() {
    if (_receiveDeviceToken != null) {
      _receiveDeviceToken.cancel();
    }
    if (_receiveMessage != null) {
      _receiveMessage.cancel();
    }
    if (_receiveNotification != null) {
      _receiveNotification.cancel();
    }
    if (_launchNotification != null) {
      _launchNotification.cancel();
    }
    if (_resumeNotification != null) {
      _resumeNotification.cancel();
    }
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Fake Push Demo'),
      ),
      body: Center(
        child: GestureDetector(
          child: Text('${Platform.operatingSystem}'),
          onTap: () {},
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  fake_push: ^0.5.4

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:fake_push/fake_push.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
51
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
89
Overall:
Weighted score of the above. [more]
73
Learn more about scoring.

We analyzed this package on Jul 2, 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:fake_push/fake_push.dart] that declares support for platforms: android, ios

Package does not support Flutter platform macos

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

Package does not support Flutter platform web

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

Package does not support Flutter platform windows

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

Package not compatible with SDK dart

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

Maintenance suggestions

The package description is too short. (-11 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.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
jaguar_serializer >=2.2.12 <3.0.0 2.2.12
meta >=1.1.6 <2.0.0 1.1.8
Transitive dependencies
collection 1.14.12 1.14.13
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
build_runner any
flutter_test
jaguar_serializer_cli any
pedantic >=1.4.0 <3.0.0
shared_preferences ^0.4.3