Flutter集成激光推送

  • Post author:
  • Post category:其他


Flutter激光官方插件地址:

https://pub.flutter-io.cn/packages/jpush_flutter

安装:

在工程 pubspec.yaml 中加入 dependencies

dependencies:
  jpush_flutter: 0.1.0

配置

Android:

在 /android/app/build.gradle 中添加下列代码:

android: {
  ....
  defaultConfig {
    applicationId "替换成自己应用 ID"  // 包名
    ...
    ndk {
    //选择要添加的对应 cpu 类型的 .so 库。
    abiFilters 'armeabi', 'armeabi-v7a', 'x86', 'x86_64', 'mips', 'mips64', 'arm64-v8a',        
    }

    manifestPlaceholders = [
        JPUSH_PKGNAME : applicationId,
        JPUSH_APPKEY : "appkey", // //JPush上注册的包名对应的appkey.
        JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可.
    ]
  }    
}

使用:

import 'package:jpush_flutter/jpush_flutter.dart';

在MyHomePage中初始化

JPush jpush = new JPush();
void initState() {
    super.initState();
    jpush.setup(appKey: AppKey ,channel: 'developer-default');
    // 监听jpush
    jpush.addEventHandler(
        onReceiveNotification: (Map<String, dynamic> message) async {
          print("flutter 接收到推送: $message");
        },
        onOpenNotification: (Map<String, dynamic> message) {
         // 点击通知栏消息,在此时通常可以做一些页面跳转等
      
        },
    );
  }

本地消息

var fireDate = DateTime.fromMillisecondsSinceEpoch(DateTime.now().millisecondsSinceEpoch);
var localNotification = LocalNotification(
        id: 123,
        title: '测试本地推送',
        buildId: 1,
        content: '我是本地推送的消息',
        fireTime: fireDate,
        subtitle: 'ios 消息推送', //该参数只有在iOS有效
        badge: 5, // 该参数只有在iOS有效
        extras: {"fa": "0"} // 设置extras,extras需要是Map<String, String>
    );



版权声明:本文为qq233325332原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。