jpush_flutter 0.0.5

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 74

QQ Group

JPush Flutter Plugin

安装

在工程 pubspec.yaml 中加入 dependencies

dependencies:
  jpush_flutter: 0.0.5

配置

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", // NOTE: JPush 上注册的包名对应的 Appkey.
        JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可.
    ]
  }    
}
iOS:
  • 在 iOS 工程中设置 TARGETS-> BUILD Phases -> LinkBinary with Libraries 找到 UserNotifications.framework 把 status 设为 optional
  • 在 xcode8 之后需要点开推送选项: TARGETS -> Capabilities -> Push Notification 设为 on 状态

使用

import 'package:jpush_flutter/jpush_flutter.dart';

APIs

注意 : 需要先调用 JPush.setup 来初始化插件,才能保证其他功能正常工作。

参考

0.0.2

修复 android 类名文件名不匹配问题。

0.0.1

第一个版本。

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:jpush_flutter/jpush_flutter.dart';

void main() => runApp(new MyApp());

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

class _MyAppState extends State<MyApp> {
  String debugLable = 'Unknown';
final JPush jpush = new JPush();
  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    

    // Platform messages may fail, so we use a try/catch PlatformException.
    jpush.getRegistrationID().then((rid) {
      setState(() {
          debugLable = "flutter getRegistrationID: $rid";
        });
    });

    jpush.setup(
      appKey: "a1703c14b186a68a66ef86c1",
      channel: "theChannel",
      production: false
      );
    jpush.applyPushAuthority(new NotificationSettingsIOS(
      sound: false,
      alert: false,
      badge: false));

    try {
      
      jpush.addEventHandler(
        onReceiveNotification: (Map<String, dynamic> message) async {
        // print("flutter onReceiveNotification: $message");
        // setState(() {
        //     _platformVersion = "flutter onReceiveNotification: $message";
        //   });
      },
      onOpenNotification: (Map<String, dynamic> message) async {
        print("flutter onOpenNotification: $message");
        setState(() {
            debugLable = "flutter onOpenNotification: $message";
          });
      },
      onReceiveMessage: (Map<String, dynamic> message) async {
        print("flutter onReceiveMessage: $message");
        
      },
      );

    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // 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;

    setState(() {
      debugLable = platformVersion;
    });
  }



// 编写视图
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: const Text('Plugin example app'),
        ),
        body: new Center(
          child: new Column(
            children:[
              new Text('result: $debugLable\n'), 
              new FlatButton(
              child: new Text('sendLocalNotification\n'), 
              onPressed: () {
                // 三秒后出发本地推送
                var fireDate = DateTime.fromMillisecondsSinceEpoch(DateTime.now().millisecondsSinceEpoch + 3000);
                var localNotification = LocalNotification(
                    id: 234,
                    title: 'fadsfa',
                    buildId: 1,
                    content: 'fdas',
                    fireTime: fireDate,
                    subtitle: 'fasf',
                    badge: 5,
                    extras: {"fa": "0"}
                  );
                jpush.sendLocalNotification(localNotification).then((res) {
                  setState(() {
                      debugLable = res;
                    });
                });

              }),

              new FlatButton(
              child: new Text('applyPushAuthority\n'), 
              onPressed: () {
                jpush.applyPushAuthority(NotificationSettingsIOS(badge: true, alert: true, sound: true));
              }),
              new FlatButton(
                child: new Text('setTags\n'), 
                onPressed: () {
                  jpush.setTags(["lala","haha"]).then((map) {
                    var tags = map['tags'];
                    setState(() {
                      debugLable = "set tags success: $map $tags";
                    });
                  })
                  .catchError((error) {
                    setState(() {
                      debugLable = "set tags error: $error";
                    });
                  }) ;
                }),
              new FlatButton(
              child: new Text('cleanTags\n'), 
              onPressed: () {
                    jpush.cleanTags().then((map) {
                    var tags = map['tags'];
                    setState(() {
                      debugLable = "cleanTags success: $map $tags";
                    });
                  })
                  .catchError((error) {
                    setState(() {
                      debugLable = "cleanTags error: $error";
                    });
                  }) ;
              }),
              new FlatButton(
                child: new Text('addTags\n'), 
                onPressed: () {
                  
                    jpush.addTags(["lala","haha"]).then((map) {
                    var tags = map['tags'];
                    setState(() {
                      debugLable = "addTags success: $map $tags";
                    });
                  })
                  .catchError((error) {
                    setState(() {
                      debugLable = "addTags error: $error";
                    });
                  }) ;

                }),
              new FlatButton(
                child: new Text('deleteTags\n'), 
                onPressed: () {
                  
                  jpush.deleteTags(["lala","haha"]).then((map) {
                    var tags = map['tags'];
                    setState(() {
                      debugLable = "deleteTags success: $map $tags";
                    });
                  })
                  .catchError((error) {
                    setState(() {
                      debugLable = "deleteTags error: $error";
                    });
                  }) ;

                }),
              new FlatButton(
                child: new Text('getAllTags\n'), 
                onPressed: () {
                  
                  jpush.getAllTags().then((map) {
                    setState(() {
                      debugLable = "getAllTags success: $map";
                    });
                  })
                  .catchError((error) {
                    setState(() {
                      debugLable = "getAllTags error: $error";
                    });
                  }) ;

                }),
              new FlatButton(
                child: new Text('setAlias\n'), 
                onPressed: () {
                  
                  jpush.setAlias("thealias11").then((map) {
                    setState(() {
                      debugLable = "setAlias success: $map";
                    });
                  })
                  .catchError((error) {
                    setState(() {
                      debugLable = "setAlias error: $error";
                    });
                  }) ;

                }),
              new FlatButton(
                child: new Text('deleteAlias\n'), 
                onPressed: () {
                  
                  jpush.deleteAlias().then((map) {
                    setState(() {
                      debugLable = "deleteAlias success: $map";
                    });
                  })
                  .catchError((error) {
                    setState(() {
                      debugLable = "deleteAlias error: $error";
                    });
                  }) ;

                }),
              new FlatButton(
                child: new Text('setBadge\n'), 
                onPressed: () {
                  
                  jpush.setBadge(66).then((map) {
                    setState(() {
                      debugLable = "setBadge success: $map";
                    });
                  })
                  .catchError((error) {
                    setState(() {
                      debugLable = "setBadge error: $error";
                    });
                  }) ;

                }),
              new FlatButton(
                child: new Text('stopPush\n'), 
                onPressed: () {
                  
                  jpush.stopPush();

                }),
              new FlatButton(
                child: new Text('resumePush\n'), 
                onPressed: () {
                  
                  jpush.resumePush();

                }),
              new FlatButton(
                child: new Text('clearAllNotifications\n'), 
                onPressed: () {
                  
                  jpush.clearAllNotifications();

                }),
              new FlatButton(
                child: new Text('getLaunchAppNotification\n'), 
                onPressed: () {
                  
                  jpush.getLaunchAppNotification().then((map) {
                    setState(() {
                      debugLable = "getLaunchAppNotification success: $map";
                    });
                  })
                  .catchError((error) {
                    setState(() {
                      debugLable = "getLaunchAppNotification error: $error";
                    });
                  });

                }),
                
            ]
          )
          
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  jpush_flutter: ^0.0.5

2. Install it

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.

3. Import it

Now in your Dart code, you can use:


import 'package:jpush_flutter/jpush_flutter.dart';
  
Version Uploaded Documentation Archive
0.0.5 Oct 8, 2018 Go to the documentation of jpush_flutter 0.0.5 Download jpush_flutter 0.0.5 archive
0.0.3 Sep 29, 2018 Go to the documentation of jpush_flutter 0.0.3 Download jpush_flutter 0.0.3 archive
0.0.2 Sep 19, 2018 Go to the documentation of jpush_flutter 0.0.2 Download jpush_flutter 0.0.2 archive
0.0.1 Sep 19, 2018 Go to the documentation of jpush_flutter 0.0.1 Download jpush_flutter 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
61
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]
74
Learn more about scoring.

We analyzed this package on Oct 10, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.4
  • Flutter: 0.9.5

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/jpush_flutter.dart.

Run flutter format to format lib/jpush_flutter.dart.

Maintenance suggestions

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Package is pre-v0.1 release. (-10 points)

While there is nothing inherently wrong with versions of 0.0.*, it usually means that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
platform ^2.0.0 2.2.0
Transitive dependencies
collection 1.14.11
meta 1.1.6
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
mockito ^3.0.0
test ^1.3.0