tpns_flutter_plugin 1.1.0 copy "tpns_flutter_plugin: ^1.1.0" to clipboard
tpns_flutter_plugin: ^1.1.0 copied to clipboard

TPNS flutter插件.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';
import 'package:tpns_flutter_plugin/tpns_flutter_plugin.dart';
import 'package:rflutter_alert/rflutter_alert.dart';
import 'ios/homeTest.dart';

void main() => runApp(new MaterialApp(
      home: new MyApp(),
      debugShowCheckedModeBanner: false,
    ));

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

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    /// 开启DEBUG
    XgFlutterPlugin().setEnableDebug(true);

    /// 添加回调事件
    XgFlutterPlugin().addEventHandler(
      onRegisteredDeviceToken: (String msg) async {
        print("flutter onRegisteredDeviceToken: $msg");
      },
      onRegisteredDone: (String msg) async {
        print("flutter onRegisteredDone: $msg");
        _showAlert("注册成功");
      },
      unRegistered: (String msg) async {
        print("flutter unRegistered: $msg");
        _showAlert(msg);
      },
      onReceiveNotificationResponse: (Map<String, dynamic> msg) async {
        print("flutter onReceiveNotificationResponse $msg");
      },
      onReceiveMessage: (Map<String, dynamic> msg) async {
        print("flutter onReceiveMessage $msg");
      },
      xgPushDidSetBadge: (String msg) async {
        print("flutter xgPushDidSetBadge: $msg");

        /// 在此可设置应用角标
        /// XgFlutterPlugin().setAppBadge(0);
        _showAlert(msg);
      },
      xgPushDidBindWithIdentifier: (String msg) async {
        print("flutter xgPushDidBindWithIdentifier: $msg");
        _showAlert(msg);
      },
      xgPushDidUnbindWithIdentifier: (String msg) async {
        print("flutter xgPushDidUnbindWithIdentifier: $msg");
        _showAlert(msg);
      },
      xgPushDidUpdatedBindedIdentifier: (String msg) async {
        print("flutter xgPushDidUpdatedBindedIdentifier: $msg");
        _showAlert(msg);
      },
      xgPushDidClearAllIdentifiers: (String msg) async {
        print("flutter xgPushDidClearAllIdentifiers: $msg");
        _showAlert(msg);
      },
      xgPushClickAction: (Map<String, dynamic> msg) async {
        print("flutter xgPushClickAction $msg");
        _showAlert("flutter xgPushClickAction");
      },
    );

    /// 如果您的应用非广州集群则需要在startXG之前调用此函数
    /// 香港:tpns.hk.tencent.com
    /// 新加坡:tpns.sgp.tencent.com
    /// 上海:tpns.sh.tencent.com
    // XgFlutterPlugin().configureClusterDomainName("tpns.hk.tencent.com");

    /// 启动TPNS服务
    XgFlutterPlugin().startXg("1600007893", "IX4BGYYG8L4L");
  }

  void _showAlert(String title) {
    Alert(context: context, title: title, buttons: [
      DialogButton(
        onPressed: () {
          Navigator.pop(context);
        },
        child: Text(
          "确认",
          style: TextStyle(color: Colors.white, fontSize: 20),
        ),
      )
    ]).show();
  }

  @override
  Widget build(BuildContext context) {
    return HomeTest();
  }
}
3
likes
130
points
37
downloads

Publisher

unverified uploader

Weekly Downloads

TPNS flutter插件.

Repository (GitHub)

Documentation

API reference

License

unknown (license)

Dependencies

flutter

More

Packages that depend on tpns_flutter_plugin