• Stars
    star
    142
  • Rank 258,495 (Top 6 %)
  • Language
    Objective-C
  • License
    Other
  • Created over 6 years ago
  • Updated almost 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Flutter版本jpush

pub package

flutter_jpush

Flutter 版本 jpush(极光推送),经过热心网友帮助,终于开发完成,目前功能比较稳定,已经上到pub。

ROADMAP

  • ios
  • android
  • 集成notification
  • 集成message
  • 集成alias
  • 集成tags
  • 后台接口放出服务
  • 可以运行的例子
  • 用户可相互自行推送

准备工作

申请key

进入这里申请key

ios 证书申请

不熟悉怎么申请戳这里

集成

ios 集成

ios 修改 AppDelegate.m,新版本一行代码就可以集成了

增加
#include "FlutterJPushPlugin.h"

增加
 [self startupJPush:launchOptions appKey:@"你的key" channel:@"你的渠道" isProduction:是否生产版本];

全部的AppDelegate.m如下:

#include "AppDelegate.h"
#include "GeneratedPluginRegistrant.h"
#include "FlutterJPushPlugin.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

   [self startupJPush:launchOptions appKey:@"你的key" channel:@"你的渠道" isProduction:是否生产版本];
    [GeneratedPluginRegistrant registerWithRegistry:self];
  // Override point for customization after application launch.
  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}


@end

android 集成

修改 你的项目目录/android/app/build.gradle

android/defaultConfig节点修改manifestPlaceholders,新增极光推送key配置

android {
    .... 你的代码

    defaultConfig {
        .....
        manifestPlaceholders = [
               JPUSH_PKGNAME : applicationId,
               JPUSH_APPKEY : "你的极光推送key", //JPush上注册的包名对应的appkey.
               JPUSH_CHANNEL : "你的推送渠道,如果不知道填写developer-default即可",
        ]

    }

API调用

1、启动

dart:

在程序入口处做一下调用

void _startupJpush() async {
    print("初始化jpush");
    await FlutterJPush.startup();
    print("初始化jpush成功");
  }

2、获取设备唯一号

jpush在启动的时候会去连接自己的服务器,连接并注册成功之后会返回一个唯一的设备号(registrationId),

有两种方法可以得到

设置一个监听


FlutterJPush.addnetworkDidLoginListener((String registrationId) {
      setState(() {
        /// 用于推送
        print("收到设备号:$registrationId");
        this.registrationId = registrationId;
      });
    });

或者主动去取

await FlutterJPush.getRegistrationID()

主动去取有可能取出来是空的

3、设置tag

每一个设备可以对应多个tag


/// 设置tags
 FlutterJPush.setTags( ["tag1","tag2" );
 
/// 新增tag
 JPushResult result = await FlutterJPush.addTags(["tag1","tag2"]);

/// 获取所有tag
  FlutterJPush.getAllTags();

4、设置和获取alias

alias为别名,别名一般来说是惟一的。


/// 获取别名
FlutterJPush.getAlias().then((JPushResult result) {
      if (result.isOk) {
        setState(() {
          if (mounted) _text = r.result;
        });
      }
    });

/// 设置别名

 JPushResult result = await FlutterJPush.getAlias();
if (result.isOk) {
    //设置成功
}
            


5、收到通知提醒

要处理两个监听,一个是收到了通知提醒,并出现在状态栏上面;一个是用户点击了状态栏上面的提醒,打开通知。

  FlutterJPush
        .addReceiveNotificationListener((JPushNotification notification) {
      setState(() {
        /// 收到推送
        print("收到推送提醒: $notification");
        notificationList.add(notification);
      });
    });

    FlutterJPush
        .addReceiveOpenNotificationListener((JPushNotification notification) {
      setState(() {
        print("打开了推送提醒: $notification");

        /// 打开了推送提醒
        notificationList.add(notification);
      });
    });

6、收到自定义消息

消息是服务端发送的一段代码,一般是json格式,app在收到消息之后,一般不直接做前台通知。

设置收到自定义消息的监听


    FlutterJPush.addReceiveCustomMsgListener((JPushMessage msg) {
      setState(() {
        print("收到推送消息提醒: $msg");

        /// 打开了推送提醒
        notificationList.add(msg);
      });
    });

7、停止和继续接收消息

 /// 停止推送,调用该方法后将不再受到推送
  static Future<void> stopPush() async
// 恢复推送功能,停止推送后,可调用该方法重新获得推送能力
  static Future<void> resumePush() async

目前这个版本还存在编译问题,flutter官方也在积极解决

真机运行报错couldn't find "libflutter.so"

暂时的解决方法有:

build.gradle设置

ndk{
     abiFilters 'armeabi', 'armeabi-v7a'//, 'arm64-v8a'
}

或者可以增加编译选项:

--target-platform android-arm64 或者 --target-platform android-arm

还有疑问的话可以发issue或者加qq群854192563交流

More Repositories

1

flutter_swiper

The best swiper for flutter , with multiple layouts, infinite loop. Compatible with Android & iOS.
Dart
3,501
star
2

transformer_page_view

PageTransformer for flutter
Dart
518
star
3

flutter_amap_location

高德地图flutter定位组件
Dart
274
star
4

flutter_dropdown_menu

A dropdown menu for Flutter.
Dart
265
star
5

flutter_page_indicator

Page indicator for flutter, with multiple build-in layouts.
Dart
180
star
6

flutter_amap

A Flutter plugin use amap.高德地图flutter组件
Objective-C
136
star
7

flutter_alipay

A flutter plugin to use alipay.
Dart
135
star
8

flutter_refresh

A Flutter plugin for refreshing every scrollable view by pulling down-up.
Dart
71
star
9

flutter_location_picker

A location area picker for flutter 省市区位置选择器
Dart
63
star
10

sweetalert

sweetalert for flutter
Dart
56
star
11

flutter_wechat_ble

ble 4.0 with wechat style api for flutter. flutter版微信api风格的低功耗蓝牙
Dart
53
star
12

gbk2utf8

A flutter package to convert gbk to utf-8
Dart
43
star
13

flutter-lover

我们是一群热爱flutter的开发者,我们的目标是让更多人爱上flutter,让移动开发变得更加高效、简单。
36
star
14

easy_alert

A package for flutter to use alert and toast within one line code.
Dart
32
star
15

disk_lru_cache

Disk lru cache for flutter.
Dart
31
star
16

flutter_baidu_location

A flutter plugin for baidu geo location.百度地图定位flutter插件
Dart
22
star
17

linker

A plugin for flutter to link with other app.
Dart
21
star
18

lazy_indexed_stack

懒加载IndexedStack,IndexedStack默认全部加载children,在某些情况下我们不希望这样,lazy_indexed_stack在index被访问之后才加载对应的视图
Dart
20
star
19

flutter_statusbar

A flutter plugin to fetch statusbar info like height.
Ruby
16
star
20

binding_helper

A easy way to use WidgetsBind like get rect of your widget
Dart
10
star
21

flutter_easy_nfc

nfc for flutter,android only
Java
7
star
22

dva

dva for flutter, flutter版dva。
Dart
4
star
23

flutter_rongcloud

融云im flutter版本,开发中
Dart
4
star
24

flutter_umpush

flutter友盟推送插件
3
star
25

flutter_issue

flutter的问题、坑汇总,总结便于大家查找
3
star
26

puremvc

flutter版本puremvc
Dart
2
star
27

refresh_view

Dart
2
star
28

flutter_awesome

flutter资源整理, flutter教程、flutter开源库、flutter问题汇总、flutter文章
1
star