Merge pull request #93 from raoxudong/dev

v0.3.0
master
raoxudong 5 years ago committed by GitHub
commit ead3665769
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,4 +1,4 @@
# Generated by pub on 2019-09-25 15:21:45.301321. # Generated by pub on 2019-11-19 13:53:32.095797.
analyzer:file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/analyzer-0.37.0/lib/ analyzer:file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/analyzer-0.37.0/lib/
args:file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/args-1.5.2/lib/ args:file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/args-1.5.2/lib/
async:file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/async-2.3.0/lib/ async:file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/async-2.3.0/lib/
@ -19,7 +19,7 @@ io:file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/io-0.3.3/lib
js:file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/js-0.6.1+1/lib/ js:file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/js-0.6.1+1/lib/
kernel:file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/kernel-0.3.20/lib/ kernel:file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/kernel-0.3.20/lib/
matcher:file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/matcher-0.12.5/lib/ matcher:file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/matcher-0.12.5/lib/
meta:file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/meta-1.1.6/lib/ meta:file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/meta-1.1.7/lib/
mime:file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/mime-0.9.6+3/lib/ mime:file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/mime-0.9.6+3/lib/
mockito:file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/mockito-3.0.2/lib/ mockito:file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/mockito-3.0.2/lib/
multi_server_socket:file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/multi_server_socket-1.0.2/lib/ multi_server_socket:file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/multi_server_socket-1.0.2/lib/

@ -1,3 +1,7 @@
## 0.3.0
+ 新增:清除通知栏单条通知方法
+ 修复:点击通知栏无法获取消息问题
+ 同步最新版 SDK
## 0.2.0 ## 0.2.0
+ 适配最新版本 JPush SDK + 适配最新版本 JPush SDK
+ Android 支持设置角标 badge + Android 支持设置角标 badge

@ -7,7 +7,7 @@
```yaml ```yaml
dependencies: dependencies:
jpush_flutter: 0.2.0 jpush_flutter: 0.3.0
//github //github
dependencies: dependencies:

@ -34,8 +34,8 @@ android {
} }
dependencies { dependencies {
implementation 'cn.jiguang.sdk:jpush:3.3.4' implementation 'cn.jiguang.sdk:jpush:3.4.0'
implementation 'cn.jiguang.sdk:jcore:2.1.2' implementation 'cn.jiguang.sdk:jcore:2.1.6'
// implementation 'com.android.support:appcompat-v7:28.+' // implementation 'com.android.support:appcompat-v7:28.+'
compileOnly files('libs/flutter.jar') compileOnly files('libs/flutter.jar')

@ -12,6 +12,7 @@ import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel; import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler; import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result; import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.Registrar; import io.flutter.plugin.common.PluginRegistry.Registrar;
import java.util.ArrayList; import java.util.ArrayList;
@ -23,17 +24,26 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import cn.jpush.android.api.JPushInterface; import cn.jpush.android.api.JPushInterface;
import io.flutter.view.FlutterNativeView;
/** JPushPlugin */ /** JPushPlugin */
public class JPushPlugin implements MethodCallHandler { public class JPushPlugin implements MethodCallHandler {
/** Plugin registration. */ /** Plugin registration. */
public static void registerWith(Registrar registrar) { public static void registerWith(Registrar registrar) {
final MethodChannel channel = new MethodChannel(registrar.messenger(), "jpush"); final MethodChannel channel = new MethodChannel(registrar.messenger(), "jpush");
channel.setMethodCallHandler(new JPushPlugin(registrar, channel)); channel.setMethodCallHandler(new JPushPlugin(registrar, channel));
registrar.addViewDestroyListener(new PluginRegistry.ViewDestroyListener() {
@Override
public boolean onViewDestroy(FlutterNativeView flutterNativeView) {
instance.dartIsReady = false;
return false;
}
});
} }
private static String TAG = "| JPUSH | Android | "; private static String TAG = "| JPUSH | Flutter | Android | ";
public static JPushPlugin instance; public static JPushPlugin instance;
static List<Map<String, Object>> openNotificationCache = new ArrayList<>(); static List<Map<String, Object>> openNotificationCache = new ArrayList<>();
@ -86,6 +96,8 @@ public class JPushPlugin implements MethodCallHandler {
resumePush(call, result); resumePush(call, result);
} else if (call.method.equals("clearAllNotifications")) { } else if (call.method.equals("clearAllNotifications")) {
clearAllNotifications(call, result); clearAllNotifications(call, result);
} else if (call.method.equals("clearNotification")) {
clearNotification(call,result);
} else if (call.method.equals("getLaunchAppNotification")) { } else if (call.method.equals("getLaunchAppNotification")) {
getLaunchAppNotification(call, result); getLaunchAppNotification(call, result);
} else if (call.method.equals("getRegistrationID")) { } else if (call.method.equals("getRegistrationID")) {
@ -133,6 +145,7 @@ public class JPushPlugin implements MethodCallHandler {
if (ridAvailable && dartIsReady) { if (ridAvailable && dartIsReady) {
// try to schedule get rid cache // try to schedule get rid cache
for (Result res: JPushPlugin.instance.getRidCache) { for (Result res: JPushPlugin.instance.getRidCache) {
Log.d(TAG,"scheduleCache rid = " + rid);
res.success(rid); res.success(rid);
JPushPlugin.instance.getRidCache.remove(res); JPushPlugin.instance.getRidCache.remove(res);
} }
@ -220,6 +233,13 @@ public class JPushPlugin implements MethodCallHandler {
JPushInterface.clearAllNotifications(registrar.context()); JPushInterface.clearAllNotifications(registrar.context());
} }
public void clearNotification(MethodCall call, Result result) {
Log.d(TAG,"clearNotification: ");
Object id = call.arguments;
if (id != null) {
JPushInterface.clearNotificationById(registrar.context(),(int)id);
}
}
public void getLaunchAppNotification(MethodCall call, Result result) { public void getLaunchAppNotification(MethodCall call, Result result) {
Log.d(TAG,""); Log.d(TAG,"");

@ -0,0 +1,10 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/Applications/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/raoxudong/JPush/jpush-github/jpush-flutter-plugin/example"
export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build/ios"
export "FLUTTER_FRAMEWORK_DIR=/Applications/flutter/bin/cache/artifacts/engine/ios"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"

@ -13,7 +13,7 @@ class MyApp extends StatefulWidget {
class _MyAppState extends State<MyApp> { class _MyAppState extends State<MyApp> {
String debugLable = 'Unknown'; String debugLable = 'Unknown';
final JPush jpush = new JPush(); final JPush jpush = new JPush();
@override @override
void initState() { void initState() {
super.initState(); super.initState();
@ -25,26 +25,7 @@ final JPush jpush = new JPush();
String platformVersion; 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,
debug: true,
);
jpush.applyPushAuthority(new NotificationSettingsIOS(
sound: true,
alert: true,
badge: true));
try { try {
jpush.addEventHandler( jpush.addEventHandler(
onReceiveNotification: (Map<String, dynamic> message) async { onReceiveNotification: (Map<String, dynamic> message) async {
print("flutter onReceiveNotification: $message"); print("flutter onReceiveNotification: $message");
@ -70,6 +51,28 @@ final JPush jpush = new JPush();
platformVersion = 'Failed to get platform version.'; platformVersion = 'Failed to get platform version.';
} }
jpush.setup(
appKey: "你自己应用的 AppKey",
channel: "theChannel",
production: false,
debug: true,
);
jpush.applyPushAuthority(new NotificationSettingsIOS(
sound: true,
alert: true,
badge: true));
// Platform messages may fail, so we use a try/catch PlatformException.
jpush.getRegistrationID().then((rid) {
print("flutter get registration id : $rid");
setState(() {
debugLable = "flutter getRegistrationID: $rid";
});
});
// If the widget was removed from the tree while the asynchronous platform // 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 // message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance. // setState to update our non-existent appearance.
@ -94,9 +97,11 @@ final JPush jpush = new JPush();
child: new Column( child: new Column(
children:[ children:[
new Text('result: $debugLable\n'), new Text('result: $debugLable\n'),
new FlatButton( new Row(
child: new Text('sendLocalNotification\n'), mainAxisAlignment: MainAxisAlignment.center,
onPressed: () { children: <Widget>[
new Text(" "),
new CustomButton(title: "sendLocalNotification", onPressed: (){
// //
var fireDate = DateTime.fromMillisecondsSinceEpoch(DateTime.now().millisecondsSinceEpoch + 3000); var fireDate = DateTime.fromMillisecondsSinceEpoch(DateTime.now().millisecondsSinceEpoch + 3000);
var localNotification = LocalNotification( var localNotification = LocalNotification(
@ -114,12 +119,9 @@ final JPush jpush = new JPush();
debugLable = res; debugLable = res;
}); });
}); });
}), }),
new FlatButton( new Text(" "),
child: new Text('getLaunchAppNotification\n'), new CustomButton(title: "getLaunchAppNotification", onPressed: (){
onPressed: () {
jpush.getLaunchAppNotification().then((map) { jpush.getLaunchAppNotification().then((map) {
setState(() { setState(() {
debugLable = "getLaunchAppNotification success: $map"; debugLable = "getLaunchAppNotification success: $map";
@ -130,16 +132,13 @@ final JPush jpush = new JPush();
debugLable = "getLaunchAppNotification error: $error"; debugLable = "getLaunchAppNotification error: $error";
}); });
}); });
}),
new FlatButton(
child: new Text('applyPushAuthority\n'),
onPressed: () {
jpush.applyPushAuthority(NotificationSettingsIOS(badge: true, alert: true, sound: true));
}), }),
new FlatButton( ]),
child: new Text('setTags\n'), new Row(
onPressed: () { mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text(" "),
new CustomButton(title: "setTags", onPressed: (){
jpush.setTags(["lala","haha"]).then((map) { jpush.setTags(["lala","haha"]).then((map) {
var tags = map['tags']; var tags = map['tags'];
setState(() { setState(() {
@ -152,42 +151,21 @@ final JPush jpush = new JPush();
}); });
}) ; }) ;
}), }),
new FlatButton( new Text(" "),
child: new Text('cleanTags\n'), new CustomButton(title: "addTags", onPressed: (){
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) { jpush.addTags(["lala","haha"]).then((map) {
var tags = map['tags']; var tags = map['tags'];
setState(() { setState(() {
debugLable = "addTags success: $map $tags"; debugLable = "addTags success: $map $tags";
}); });
}) }).catchError((error) {
.catchError((error) {
setState(() { setState(() {
debugLable = "addTags error: $error"; debugLable = "addTags error: $error";
}); });
}) ; }) ;
}), }),
new FlatButton( new Text(" "),
child: new Text('deleteTags\n'), new CustomButton(title: "deleteTags", onPressed: (){
onPressed: () {
jpush.deleteTags(["lala","haha"]).then((map) { jpush.deleteTags(["lala","haha"]).then((map) {
var tags = map['tags']; var tags = map['tags'];
setState(() { setState(() {
@ -199,12 +177,14 @@ final JPush jpush = new JPush();
debugLable = "deleteTags error: $error"; debugLable = "deleteTags error: $error";
}); });
}) ; }) ;
}), }),
new FlatButton( ]
child: new Text('getAllTags\n'), ),
onPressed: () { new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text(" "),
new CustomButton(title: "getAllTags", onPressed: (){
jpush.getAllTags().then((map) { jpush.getAllTags().then((map) {
setState(() { setState(() {
debugLable = "getAllTags success: $map"; debugLable = "getAllTags success: $map";
@ -215,12 +195,28 @@ final JPush jpush = new JPush();
debugLable = "getAllTags error: $error"; debugLable = "getAllTags error: $error";
}); });
}) ; }) ;
}), }),
new FlatButton( new Text(" "),
child: new Text('setAlias\n'), new CustomButton(title: "cleanTags", onPressed: (){
onPressed: () { jpush.cleanTags().then((map) {
var tags = map['tags'];
setState(() {
debugLable = "cleanTags success: $map $tags";
});
})
.catchError((error) {
setState(() {
debugLable = "cleanTags error: $error";
});
}) ;
}),
]
),
new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text(" "),
new CustomButton(title: "setAlias", onPressed: (){
jpush.setAlias("thealias11").then((map) { jpush.setAlias("thealias11").then((map) {
setState(() { setState(() {
debugLable = "setAlias success: $map"; debugLable = "setAlias success: $map";
@ -231,12 +227,9 @@ final JPush jpush = new JPush();
debugLable = "setAlias error: $error"; debugLable = "setAlias error: $error";
}); });
}) ; }) ;
}), }),
new FlatButton( new Text(" "),
child: new Text('deleteAlias\n'), new CustomButton(title: "deleteAlias", onPressed: (){
onPressed: () {
jpush.deleteAlias().then((map) { jpush.deleteAlias().then((map) {
setState(() { setState(() {
debugLable = "deleteAlias success: $map"; debugLable = "deleteAlias success: $map";
@ -247,12 +240,32 @@ final JPush jpush = new JPush();
debugLable = "deleteAlias error: $error"; debugLable = "deleteAlias error: $error";
}); });
}) ; }) ;
}), }),
new FlatButton(
child: new Text('setBadge\n'),
onPressed: () {
]
),
new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text(" "),
new CustomButton(title: "stopPush",onPressed: (){
jpush.stopPush();
}),
new Text(" "),
new CustomButton(title: "resumePush", onPressed: (){
jpush.resumePush();
}),
],
),
new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text(" "),
new CustomButton(title: "clearAllNotifications",onPressed: (){
jpush.clearAllNotifications();
}),
new Text(" "),
new CustomButton(title: "setBadge", onPressed: (){
jpush.setBadge(66).then((map) { jpush.setBadge(66).then((map) {
setState(() { setState(() {
debugLable = "setBadge success: $map"; debugLable = "setBadge success: $map";
@ -262,37 +275,35 @@ final JPush jpush = new JPush();
setState(() { setState(() {
debugLable = "setBadge error: $error"; 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();
}), }),
],
),
] ]
) )
), ),
), ),
); );
} }
} }
///
class CustomButton extends StatelessWidget {
final VoidCallback onPressed;
final String title;
const CustomButton({@required this.onPressed, @required this.title});
@override
Widget build(BuildContext context) {
return new FlatButton(
onPressed: onPressed,
child: new Text("$title"),
color: Color(0xff585858),
highlightColor: Color(0xff888888),
splashColor: Color(0xff888888),
textColor: Colors.white,
//padding: EdgeInsets.fromLTRB(5, 5, 5, 5),
);
}
}

@ -21,14 +21,14 @@ packages:
name: async name: async
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "2.2.0" version: "2.3.0"
boolean_selector: boolean_selector:
dependency: transitive dependency: transitive
description: description:
name: boolean_selector name: boolean_selector
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.0.4" version: "1.0.5"
charcode: charcode:
dependency: transitive dependency: transitive
description: description:
@ -136,7 +136,7 @@ packages:
path: ".." path: ".."
relative: true relative: true
source: path source: path
version: "0.2.0" version: "0.3.0"
js: js:
dependency: transitive dependency: transitive
description: description:
@ -171,7 +171,7 @@ packages:
name: meta name: meta
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.1.6" version: "1.1.7"
mime: mime:
dependency: transitive dependency: transitive
description: description:
@ -220,14 +220,14 @@ packages:
name: path name: path
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.6.2" version: "1.6.4"
pedantic: pedantic:
dependency: transitive dependency: transitive
description: description:
name: pedantic name: pedantic
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.7.0" version: "1.8.0+1"
platform: platform:
dependency: transitive dependency: transitive
description: description:
@ -255,7 +255,7 @@ packages:
name: quiver name: quiver
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "2.0.3" version: "2.0.5"
shelf: shelf:
dependency: transitive dependency: transitive
description: description:
@ -330,7 +330,7 @@ packages:
name: string_scanner name: string_scanner
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.0.4" version: "1.0.5"
term_glyph: term_glyph:
dependency: transitive dependency: transitive
description: description:

@ -5,7 +5,7 @@
#import <JPush/JPUSHService.h> #import <JPush/JPUSHService.h>
#define JPLog(fmt, ...) NSLog((@"| JPUSH | iOS | " fmt), ##__VA_ARGS__) #define JPLog(fmt, ...) NSLog((@"| JPUSH | Flutter | iOS | " fmt), ##__VA_ARGS__)
@interface NSError (FlutterError) @interface NSError (FlutterError)
@property(readonly, nonatomic) FlutterError *flutterError; @property(readonly, nonatomic) FlutterError *flutterError;
@ -140,9 +140,12 @@ static NSMutableArray<FlutterResult>* getRidResults;
} else if([@"stopPush" isEqualToString:call.method]) { } else if([@"stopPush" isEqualToString:call.method]) {
[self stopPush:call result:result]; [self stopPush:call result:result];
} else if([@"resumePush" isEqualToString:call.method]) { } else if([@"resumePush" isEqualToString:call.method]) {
[self applyPushAuthority:call result:result]; JPLog(@"ios platform not support resume push.");
//[self applyPushAuthority:call result:result];
} else if([@"clearAllNotifications" isEqualToString:call.method]) { } else if([@"clearAllNotifications" isEqualToString:call.method]) {
[self clearAllNotifications:call result:result]; [self clearAllNotifications:call result:result];
} else if ([@"clearNotification" isEqualToString:call.method]) {
[self clearNotification:call result:result];
} else if([@"getLaunchAppNotification" isEqualToString:call.method]) { } else if([@"getLaunchAppNotification" isEqualToString:call.method]) {
[self getLaunchAppNotification:call result:result]; [self getLaunchAppNotification:call result:result];
} else if([@"getRegistrationID" isEqualToString:call.method]) { } else if([@"getRegistrationID" isEqualToString:call.method]) {
@ -307,10 +310,37 @@ static NSMutableArray<FlutterResult>* getRidResults;
JPLog(@"stopPush:"); JPLog(@"stopPush:");
[[UIApplication sharedApplication] unregisterForRemoteNotifications]; [[UIApplication sharedApplication] unregisterForRemoteNotifications];
} }
- (void)clearAllNotifications:(FlutterMethodCall*)call result:(FlutterResult)result { - (void)clearAllNotifications:(FlutterMethodCall*)call result:(FlutterResult)result {
JPLog(@"clearAllNotifications:"); JPLog(@"clearAllNotifications:");
[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
if (@available(iOS 10.0, *)) {
//iOS 10 以上支持
JPushNotificationIdentifier *identifier = [[JPushNotificationIdentifier alloc] init];
identifier.identifiers = nil;
identifier.delivered = YES; //等于 YES 则移除所有在通知中心显示的,等于 NO 则为移除所有待推送的
[JPUSHService removeNotification:identifier];
} else {
// iOS 10 以下移除所有推送;iOS 10 以上移除所有在通知中心显示推送和待推送请求
[JPUSHService removeNotification:nil];
}
}
- (void)clearNotification:(FlutterMethodCall*)call result:(FlutterResult)result {
JPLog(@"clearNotification:");
NSNumber *notificationId = call.arguments;
if (!notificationId) {
return ;
}
JPushNotificationIdentifier *identifier = [[JPushNotificationIdentifier alloc] init];
identifier.identifiers = @[notificationId.stringValue];
if (@available(iOS 10.0, *)) {
//iOS 10 以上有效,等于 YES 则在通知中心显示的里面移除,等于 NO 则为在待推送的里面移除;iOS 10 以下无效
identifier.delivered = YES;
} else {
// Fallback on earlier versions
}
[JPUSHService removeNotification:identifier];
} }
- (void)getLaunchAppNotification:(FlutterMethodCall*)call result:(FlutterResult)result { - (void)getLaunchAppNotification:(FlutterMethodCall*)call result:(FlutterResult)result {
@ -416,8 +446,7 @@ static NSMutableArray<FlutterResult>* getRidResults;
#pragma mark - AppDelegate #pragma mark - AppDelegate
- (BOOL)application:(UIApplication *)application - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if (launchOptions != nil) { if (launchOptions != nil) {
_launchNotification = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]; _launchNotification = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
@ -442,12 +471,12 @@ didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
} }
- (void)applicationDidEnterBackground:(UIApplication *)application { - (void)applicationDidEnterBackground:(UIApplication *)application {
// _resumingFromBackground = YES; // _resumingFromBackground = YES;
} }
- (void)applicationDidBecomeActive:(UIApplication *)application { - (void)applicationDidBecomeActive:(UIApplication *)application {
// application.applicationIconBadgeNumber = 1; // application.applicationIconBadgeNumber = 1;
// application.applicationIconBadgeNumber = 0; // application.applicationIconBadgeNumber = 0;
} }
- (bool)application:(UIApplication *)application - (bool)application:(UIApplication *)application

@ -10,7 +10,7 @@ A new flutter plugin project.
DESC DESC
s.homepage = 'http://example.com' s.homepage = 'http://example.com'
s.license = { :file => '../LICENSE' } s.license = { :file => '../LICENSE' }
s.author = { 'huminios' => '380108184@qq.com' } s.author = { 'xudong.rao' => 'xudong.rao@outlook.com' }
s.source = { :path => '.' } s.source = { :path => '.' }
s.source_files = 'Classes/**/*' s.source_files = 'Classes/**/*'
s.public_header_files = 'Classes/**/*.h' s.public_header_files = 'Classes/**/*.h'
@ -20,4 +20,3 @@ A new flutter plugin project.
s.ios.deployment_target = '8.0' s.ios.deployment_target = '8.0'
s.static_framework = true s.static_framework = true
end end

@ -3,7 +3,6 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:platform/platform.dart'; import 'package:platform/platform.dart';
typedef Future<dynamic> EventHandler(Map<String, dynamic> event); typedef Future<dynamic> EventHandler(Map<String, dynamic> event);
class JPush { class JPush {
@ -18,9 +17,8 @@ class JPush {
: _channel = channel, : _channel = channel,
_platform = platform; _platform = platform;
static final JPush _instance = new JPush.private( static final JPush _instance =
const MethodChannel('jpush'), new JPush.private(const MethodChannel('jpush'), const LocalPlatform());
const LocalPlatform());
EventHandler _onReceiveNotification; EventHandler _onReceiveNotification;
EventHandler _onOpenNotification; EventHandler _onOpenNotification;
@ -34,8 +32,14 @@ class JPush {
}) { }) {
print(flutter_log + "setup:"); print(flutter_log + "setup:");
_channel.invokeMethod('setup', { 'appKey': appKey, 'channel': channel, 'production': production, 'debug': debug}); _channel.invokeMethod('setup', {
'appKey': appKey,
'channel': channel,
'production': production,
'debug': debug
});
} }
/// ///
/// JPush () /// JPush ()
/// ///
@ -70,7 +74,8 @@ class JPush {
/// ///
/// ///
/// ///
void applyPushAuthority([NotificationSettingsIOS iosSettings = const NotificationSettingsIOS()]) { void applyPushAuthority(
[NotificationSettingsIOS iosSettings = const NotificationSettingsIOS()]) {
print(flutter_log + "applyPushAuthority:"); print(flutter_log + "applyPushAuthority:");
if (!_platform.isIOS) { if (!_platform.isIOS) {
@ -90,7 +95,8 @@ class JPush {
Future<Map<dynamic, dynamic>> setTags(List<String> tags) async { Future<Map<dynamic, dynamic>> setTags(List<String> tags) async {
print(flutter_log + "setTags:"); print(flutter_log + "setTags:");
final Map<dynamic, dynamic> result = await _channel.invokeMethod('setTags', tags); final Map<dynamic, dynamic> result =
await _channel.invokeMethod('setTags', tags);
return result; return result;
} }
@ -103,7 +109,8 @@ class JPush {
Future<Map<dynamic, dynamic>> cleanTags() async { Future<Map<dynamic, dynamic>> cleanTags() async {
print(flutter_log + "cleanTags:"); print(flutter_log + "cleanTags:");
final Map<dynamic, dynamic> result = await _channel.invokeMethod('cleanTags'); final Map<dynamic, dynamic> result =
await _channel.invokeMethod('cleanTags');
return result; return result;
} }
@ -118,7 +125,8 @@ class JPush {
Future<Map<dynamic, dynamic>> addTags(List<String> tags) async { Future<Map<dynamic, dynamic>> addTags(List<String> tags) async {
print(flutter_log + "addTags:"); print(flutter_log + "addTags:");
final Map<dynamic, dynamic> result = await _channel.invokeMethod('addTags', tags); final Map<dynamic, dynamic> result =
await _channel.invokeMethod('addTags', tags);
return result; return result;
} }
@ -132,7 +140,8 @@ class JPush {
Future<Map<dynamic, dynamic>> deleteTags(List<String> tags) async { Future<Map<dynamic, dynamic>> deleteTags(List<String> tags) async {
print(flutter_log + "deleteTags:"); print(flutter_log + "deleteTags:");
final Map<dynamic, dynamic> result = await _channel.invokeMethod('deleteTags', tags); final Map<dynamic, dynamic> result =
await _channel.invokeMethod('deleteTags', tags);
return result; return result;
} }
@ -145,7 +154,8 @@ class JPush {
Future<Map<dynamic, dynamic>> getAllTags() async { Future<Map<dynamic, dynamic>> getAllTags() async {
print(flutter_log + "getAllTags:"); print(flutter_log + "getAllTags:");
final Map<dynamic, dynamic> result = await _channel.invokeMethod('getAllTags'); final Map<dynamic, dynamic> result =
await _channel.invokeMethod('getAllTags');
return result; return result;
} }
@ -160,7 +170,8 @@ class JPush {
Future<Map<dynamic, dynamic>> setAlias(String alias) async { Future<Map<dynamic, dynamic>> setAlias(String alias) async {
print(flutter_log + "setAlias:"); print(flutter_log + "setAlias:");
final Map<dynamic, dynamic> result = await _channel.invokeMethod('setAlias', alias); final Map<dynamic, dynamic> result =
await _channel.invokeMethod('setAlias', alias);
return result; return result;
} }
@ -173,7 +184,8 @@ class JPush {
Future<Map<dynamic, dynamic>> deleteAlias() async { Future<Map<dynamic, dynamic>> deleteAlias() async {
print(flutter_log + "deleteAlias:"); print(flutter_log + "deleteAlias:");
final Map<dynamic, dynamic> result = await _channel.invokeMethod('deleteAlias'); final Map<dynamic, dynamic> result =
await _channel.invokeMethod('deleteAlias');
return result; return result;
} }
@ -187,7 +199,7 @@ class JPush {
Future setBadge(int badge) async { Future setBadge(int badge) async {
print(flutter_log + "setBadge:"); print(flutter_log + "setBadge:");
await _channel.invokeMethod('setBadge', {"badge":badge}); await _channel.invokeMethod('setBadge', {"badge": badge});
} }
/// ///
@ -217,6 +229,15 @@ class JPush {
await _channel.invokeMethod('clearAllNotifications'); await _channel.invokeMethod('clearAllNotifications');
} }
///
///
/// @param notificationId idLocalNotification id
///
void clearNotification({@required int notificationId}) {
print(flutter_log + "clearNotification:");
_channel.invokeListMethod("clearNotification",notificationId);
}
/// ///
/// iOS Only /// iOS Only
/// notification notification /// notification notification
@ -227,7 +248,8 @@ class JPush {
Future<Map<dynamic, dynamic>> getLaunchAppNotification() async { Future<Map<dynamic, dynamic>> getLaunchAppNotification() async {
print(flutter_log + "getLaunchAppNotification:"); print(flutter_log + "getLaunchAppNotification:");
final Map<dynamic, dynamic> result = await _channel.invokeMethod('getLaunchAppNotification'); final Map<dynamic, dynamic> result =
await _channel.invokeMethod('getLaunchAppNotification');
return result; return result;
} }
@ -255,6 +277,8 @@ class JPush {
return notification.toMap().toString(); return notification.toMap().toString();
} }
} }
class NotificationSettingsIOS { class NotificationSettingsIOS {
@ -262,7 +286,7 @@ class NotificationSettingsIOS {
final bool alert; final bool alert;
final bool badge; final bool badge;
const NotificationSettingsIOS ({ const NotificationSettingsIOS({
this.sound = true, this.sound = true,
this.alert = true, this.alert = true,
this.badge = true, this.badge = true,
@ -273,37 +297,31 @@ class NotificationSettingsIOS {
} }
} }
/// @property {number} [buildId] - 1 2 `setStyleCustom`
/// @property {number} [id] - id,
/// @property {string} [title] -
/// @property {string} [content] -
/// @property {object} [extra] - extra
/// @property {number} [buildId] - 1 2 `setStyleCustom` /// @property {number} [fireTime] -
/// @property {number} [id] - id, /// // iOS Only
/// @property {string} [title] - /// @property {number} [badge] -
/// @property {string} [content] - /// // iOS Only
/// @property {object} [extra] - extra /// @property {string} [soundName] -
/// @property {number} [fireTime] - /// // iOS 10+ Only
/// // iOS Only /// @property {string} [subtitle] -
/// @property {number} [badge] -
/// // iOS Only
/// @property {string} [soundName] -
/// // iOS 10+ Only
/// @property {string} [subtitle] -
class LocalNotification { class LocalNotification {
final int buildId; //?
final int buildId;//?
final int id; final int id;
final String title; final String title;
final String content; final String content;
final Map<String, String> extra;//? final Map<String, String> extra; //?
final DateTime fireTime; final DateTime fireTime;
final int badge;//? final int badge; //?
final String soundName;//? final String soundName; //?
final String subtitle;//? final String subtitle; //?
const LocalNotification ({ const LocalNotification(
@required this.id, {@required this.id,
@required this.title, @required this.title,
@required this.content, @required this.content,
@required this.fireTime, @required this.fireTime,
@ -311,9 +329,8 @@ class LocalNotification {
this.extra, this.extra,
this.badge = 0, this.badge = 0,
this.soundName, this.soundName,
this.subtitle this.subtitle})
}): : assert(id != null),
assert(id != null),
assert(title != null), assert(title != null),
assert(content != null), assert(content != null),
assert(fireTime != null); assert(fireTime != null);
@ -329,7 +346,6 @@ class LocalNotification {
'badge': badge, 'badge': badge,
'soundName': soundName, 'soundName': soundName,
'subtitle': subtitle 'subtitle': subtitle
}..removeWhere((key, value)=>value==null); }..removeWhere((key, value) => value == null);
} }
} }

@ -145,7 +145,7 @@ packages:
name: meta name: meta
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.1.6" version: "1.1.7"
mime: mime:
dependency: transitive dependency: transitive
description: description:

@ -1,7 +1,7 @@
name: jpush_flutter name: jpush_flutter
description: Offically supported JPush Flutter plugin. description: Offically supported JPush Flutter plugin.
version: 0.2.0 version: 0.3.0
author: huminios <h380108184@gmail.com> author: xudong.rao <xudong.rao@outlook.com>
homepage: https://www.jiguang.cn homepage: https://www.jiguang.cn
environment: environment:

Loading…
Cancel
Save