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();
@ -23,53 +23,56 @@ final JPush jpush = new JPush();
// Platform messages are asynchronous, so we initialize in an async method. // Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async { Future<void> initPlatformState() async {
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");
setState(() { setState(() {
debugLable = "flutter onReceiveNotification: $message"; debugLable = "flutter onReceiveNotification: $message";
}); });
}, },
onOpenNotification: (Map<String, dynamic> message) async { onOpenNotification: (Map<String, dynamic> message) async {
print("flutter onOpenNotification: $message"); print("flutter onOpenNotification: $message");
setState(() { setState(() {
debugLable = "flutter onOpenNotification: $message"; debugLable = "flutter onOpenNotification: $message";
}); });
}, },
onReceiveMessage: (Map<String, dynamic> message) async { onReceiveMessage: (Map<String, dynamic> message) async {
print("flutter onReceiveMessage: $message"); print("flutter onReceiveMessage: $message");
setState(() { setState(() {
debugLable = "flutter onReceiveMessage: $message"; debugLable = "flutter onReceiveMessage: $message";
}); });
}, },
); );
} on PlatformException { } on PlatformException {
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.
@ -93,206 +96,214 @@ final JPush jpush = new JPush();
body: new Center( body: new Center(
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(" "),
var fireDate = DateTime.fromMillisecondsSinceEpoch(DateTime.now().millisecondsSinceEpoch + 3000); new CustomButton(title: "sendLocalNotification", onPressed: (){
var localNotification = LocalNotification( //
id: 234, var fireDate = DateTime.fromMillisecondsSinceEpoch(DateTime.now().millisecondsSinceEpoch + 3000);
title: 'fadsfa', var localNotification = LocalNotification(
buildId: 1, id: 234,
content: 'fdas', title: 'fadsfa',
fireTime: fireDate, buildId: 1,
subtitle: 'fasf', content: 'fdas',
badge: 5, fireTime: fireDate,
extra: {"fa": "0"} subtitle: 'fasf',
); badge: 5,
jpush.sendLocalNotification(localNotification).then((res) { extra: {"fa": "0"}
setState(() { );
debugLable = res; jpush.sendLocalNotification(localNotification).then((res) {
}); setState(() {
}); debugLable = res;
});
}),
new FlatButton(
child: new Text('getLaunchAppNotification\n'),
onPressed: () {
jpush.getLaunchAppNotification().then((map) {
setState(() {
debugLable = "getLaunchAppNotification success: $map";
}); });
}) }),
.catchError((error) { new Text(" "),
setState(() { new CustomButton(title: "getLaunchAppNotification", onPressed: (){
debugLable = "getLaunchAppNotification error: $error"; jpush.getLaunchAppNotification().then((map) {
setState(() {
debugLable = "getLaunchAppNotification success: $map";
});
})
.catchError((error) {
setState(() {
debugLable = "getLaunchAppNotification error: $error";
});
}); });
}); }),
]),
}), new Row(
new FlatButton( mainAxisAlignment: MainAxisAlignment.center,
child: new Text('applyPushAuthority\n'), children: <Widget>[
onPressed: () { new Text(" "),
jpush.applyPushAuthority(NotificationSettingsIOS(badge: true, alert: true, sound: true)); new CustomButton(title: "setTags", onPressed: (){
}), jpush.setTags(["lala","haha"]).then((map) {
new FlatButton( var tags = map['tags'];
child: new Text('setTags\n'), setState(() {
onPressed: () { debugLable = "set tags success: $map $tags";
jpush.setTags(["lala","haha"]).then((map) { });
var tags = map['tags']; })
setState(() { .catchError((error) {
debugLable = "set tags success: $map $tags"; setState(() {
}); debugLable = "set tags error: $error";
}) });
.catchError((error) { }) ;
setState(() { }),
debugLable = "set tags error: $error"; new Text(" "),
}); new CustomButton(title: "addTags", onPressed: (){
}) ;
}),
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) { 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 Text(" "),
}), new CustomButton(title: "deleteTags", onPressed: (){
new FlatButton( jpush.deleteTags(["lala","haha"]).then((map) {
child: new Text('deleteTags\n'), var tags = map['tags'];
onPressed: () { setState(() {
debugLable = "deleteTags success: $map $tags";
jpush.deleteTags(["lala","haha"]).then((map) { });
var tags = map['tags']; })
setState(() { .catchError((error) {
debugLable = "deleteTags success: $map $tags"; setState(() {
}); debugLable = "deleteTags error: $error";
}) });
.catchError((error) { }) ;
setState(() { }),
debugLable = "deleteTags error: $error"; ]
}); ),
}) ; new Row(
mainAxisAlignment: MainAxisAlignment.center,
}), children: <Widget>[
new FlatButton( new Text(" "),
child: new Text('getAllTags\n'), new CustomButton(title: "getAllTags", onPressed: (){
onPressed: () { jpush.getAllTags().then((map) {
setState(() {
jpush.getAllTags().then((map) { debugLable = "getAllTags success: $map";
setState(() { });
debugLable = "getAllTags success: $map"; })
}); .catchError((error) {
}) setState(() {
.catchError((error) { debugLable = "getAllTags error: $error";
setState(() { });
debugLable = "getAllTags error: $error"; }) ;
}); }),
}) ; new Text(" "),
new CustomButton(title: "cleanTags", onPressed: (){
}), jpush.cleanTags().then((map) {
new FlatButton( var tags = map['tags'];
child: new Text('setAlias\n'), setState(() {
onPressed: () { debugLable = "cleanTags success: $map $tags";
});
jpush.setAlias("thealias11").then((map) { })
setState(() { .catchError((error) {
debugLable = "setAlias success: $map"; setState(() {
}); debugLable = "cleanTags error: $error";
}) });
.catchError((error) { }) ;
setState(() { }),
debugLable = "setAlias error: $error"; ]
}); ),
}) ; new Row(
mainAxisAlignment: MainAxisAlignment.center,
}), children: <Widget>[
new FlatButton( new Text(" "),
child: new Text('deleteAlias\n'), new CustomButton(title: "setAlias", onPressed: (){
onPressed: () { jpush.setAlias("thealias11").then((map) {
setState(() {
jpush.deleteAlias().then((map) { debugLable = "setAlias success: $map";
setState(() { });
debugLable = "deleteAlias success: $map"; })
}); .catchError((error) {
}) setState(() {
.catchError((error) { debugLable = "setAlias error: $error";
setState(() { });
debugLable = "deleteAlias error: $error"; }) ;
}); }),
}) ; new Text(" "),
new CustomButton(title: "deleteAlias", onPressed: (){
jpush.deleteAlias().then((map) {
setState(() {
debugLable = "deleteAlias success: $map";
});
})
.catchError((error) {
setState(() {
debugLable = "deleteAlias error: $error";
});
}) ;
}),
}), ]
new FlatButton( ),
child: new Text('setBadge\n'), new Row(
onPressed: () { mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
jpush.setBadge(66).then((map) { new Text(" "),
setState(() { new CustomButton(title: "stopPush",onPressed: (){
debugLable = "setBadge success: $map"; 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) {
setState(() {
debugLable = "setBadge success: $map";
});
})
.catchError((error) {
setState(() {
debugLable = "setBadge error: $error";
});
}); });
}) }),
.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();
}),
] ]
) )
), ),
), ),
); );
} }
} }
///
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;
@ -13,9 +13,9 @@
@implementation NSError (FlutterError) @implementation NSError (FlutterError)
- (FlutterError *)flutterError { - (FlutterError *)flutterError {
return [FlutterError errorWithCode:[NSString stringWithFormat:@"Error %d", (int)self.code] return [FlutterError errorWithCode:[NSString stringWithFormat:@"Error %d", (int)self.code]
message:self.domain message:self.domain
details:self.localizedDescription]; details:self.localizedDescription];
} }
@end @end
@ -28,489 +28,518 @@
static NSMutableArray<FlutterResult>* getRidResults; static NSMutableArray<FlutterResult>* getRidResults;
@implementation JPushPlugin { @implementation JPushPlugin {
NSDictionary *_launchNotification; NSDictionary *_launchNotification;
BOOL _isJPushDidLogin; BOOL _isJPushDidLogin;
JPAuthorizationOptions notificationTypes; JPAuthorizationOptions notificationTypes;
} }
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar { + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
getRidResults = @[].mutableCopy; getRidResults = @[].mutableCopy;
FlutterMethodChannel* channel = [FlutterMethodChannel FlutterMethodChannel* channel = [FlutterMethodChannel
methodChannelWithName:@"jpush" methodChannelWithName:@"jpush"
binaryMessenger:[registrar messenger]]; binaryMessenger:[registrar messenger]];
JPushPlugin* instance = [[JPushPlugin alloc] init]; JPushPlugin* instance = [[JPushPlugin alloc] init];
instance.channel = channel; instance.channel = channel;
[registrar addApplicationDelegate:instance]; [registrar addApplicationDelegate:instance];
[registrar addMethodCallDelegate:instance channel:channel]; [registrar addMethodCallDelegate:instance channel:channel];
} }
- (id)init { - (id)init {
self = [super init]; self = [super init];
notificationTypes = 0; notificationTypes = 0;
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter]; NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter removeObserver:self]; [defaultCenter removeObserver:self];
[defaultCenter addObserver:self [defaultCenter addObserver:self
selector:@selector(networkConnecting:) selector:@selector(networkConnecting:)
name:kJPFNetworkIsConnectingNotification name:kJPFNetworkIsConnectingNotification
object:nil]; object:nil];
[defaultCenter addObserver:self [defaultCenter addObserver:self
selector:@selector(networkRegister:) selector:@selector(networkRegister:)
name:kJPFNetworkDidRegisterNotification name:kJPFNetworkDidRegisterNotification
object:nil]; object:nil];
[defaultCenter addObserver:self [defaultCenter addObserver:self
selector:@selector(networkDidSetup:) selector:@selector(networkDidSetup:)
name:kJPFNetworkDidSetupNotification name:kJPFNetworkDidSetupNotification
object:nil]; object:nil];
[defaultCenter addObserver:self [defaultCenter addObserver:self
selector:@selector(networkDidClose:) selector:@selector(networkDidClose:)
name:kJPFNetworkDidCloseNotification name:kJPFNetworkDidCloseNotification
object:nil]; object:nil];
[defaultCenter addObserver:self [defaultCenter addObserver:self
selector:@selector(networkDidLogin:) selector:@selector(networkDidLogin:)
name:kJPFNetworkDidLoginNotification name:kJPFNetworkDidLoginNotification
object:nil]; object:nil];
[defaultCenter addObserver:self [defaultCenter addObserver:self
selector:@selector(networkDidReceiveMessage:) selector:@selector(networkDidReceiveMessage:)
name:kJPFNetworkDidReceiveMessageNotification name:kJPFNetworkDidReceiveMessageNotification
object:nil]; object:nil];
return self; return self;
} }
- (void)networkConnecting:(NSNotification *)notification { - (void)networkConnecting:(NSNotification *)notification {
_isJPushDidLogin = false; _isJPushDidLogin = false;
} }
- (void)networkRegister:(NSNotification *)notification { - (void)networkRegister:(NSNotification *)notification {
_isJPushDidLogin = false; _isJPushDidLogin = false;
} }
- (void)networkDidSetup:(NSNotification *)notification { - (void)networkDidSetup:(NSNotification *)notification {
_isJPushDidLogin = false; _isJPushDidLogin = false;
} }
- (void)networkDidClose:(NSNotification *)notification { - (void)networkDidClose:(NSNotification *)notification {
_isJPushDidLogin = false; _isJPushDidLogin = false;
} }
- (void)networkDidLogin:(NSNotification *)notification { - (void)networkDidLogin:(NSNotification *)notification {
_isJPushDidLogin = YES; _isJPushDidLogin = YES;
for (FlutterResult result in getRidResults) { for (FlutterResult result in getRidResults) {
result([JPUSHService registrationID]); result([JPUSHService registrationID]);
} }
[getRidResults removeAllObjects]; [getRidResults removeAllObjects];
} }
- (void)networkDidReceiveMessage:(NSNotification *)notification { - (void)networkDidReceiveMessage:(NSNotification *)notification {
[_channel invokeMethod:@"onReceiveMessage" arguments: [notification userInfo]]; [_channel invokeMethod:@"onReceiveMessage" arguments: [notification userInfo]];
} }
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
JPLog(@"handleMethodCall:%@",call.method); JPLog(@"handleMethodCall:%@",call.method);
if ([@"getPlatformVersion" isEqualToString:call.method]) { if ([@"getPlatformVersion" isEqualToString:call.method]) {
result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]); result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]);
} else if([@"setup" isEqualToString:call.method]) { } else if([@"setup" isEqualToString:call.method]) {
[self setup:call result: result]; [self setup:call result: result];
} else if([@"applyPushAuthority" isEqualToString:call.method]) { } else if([@"applyPushAuthority" isEqualToString:call.method]) {
[self applyPushAuthority:call result:result]; [self applyPushAuthority:call result:result];
} else if([@"setTags" isEqualToString:call.method]) { } else if([@"setTags" isEqualToString:call.method]) {
[self setTags:call result:result]; [self setTags:call result:result];
} else if([@"cleanTags" isEqualToString:call.method]) { } else if([@"cleanTags" isEqualToString:call.method]) {
[self cleanTags:call result:result]; [self cleanTags:call result:result];
} else if([@"addTags" isEqualToString:call.method]) { } else if([@"addTags" isEqualToString:call.method]) {
[self addTags:call result:result]; [self addTags:call result:result];
} else if([@"deleteTags" isEqualToString:call.method]) { } else if([@"deleteTags" isEqualToString:call.method]) {
[self deleteTags:call result:result]; [self deleteTags:call result:result];
} else if([@"getAllTags" isEqualToString:call.method]) { } else if([@"getAllTags" isEqualToString:call.method]) {
[self getAllTags:call result:result]; [self getAllTags:call result:result];
} else if([@"setAlias" isEqualToString:call.method]) { } else if([@"setAlias" isEqualToString:call.method]) {
[self setAlias:call result:result]; [self setAlias:call result:result];
} else if([@"deleteAlias" isEqualToString:call.method]) { } else if([@"deleteAlias" isEqualToString:call.method]) {
[self deleteAlias:call result:result]; [self deleteAlias:call result:result];
} else if([@"setBadge" isEqualToString:call.method]) { } else if([@"setBadge" isEqualToString:call.method]) {
[self setBadge:call result:result]; [self setBadge:call result:result];
} 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.");
} else if([@"clearAllNotifications" isEqualToString:call.method]) { //[self applyPushAuthority:call result:result];
[self clearAllNotifications:call result:result]; } else if([@"clearAllNotifications" isEqualToString:call.method]) {
} else if([@"getLaunchAppNotification" isEqualToString:call.method]) { [self clearAllNotifications:call result:result];
[self getLaunchAppNotification:call result:result]; } else if ([@"clearNotification" isEqualToString:call.method]) {
} else if([@"getRegistrationID" isEqualToString:call.method]) { [self clearNotification:call result:result];
[self getRegistrationID:call result:result]; } else if([@"getLaunchAppNotification" isEqualToString:call.method]) {
} else if([@"sendLocalNotification"isEqualToString:call.method]) { [self getLaunchAppNotification:call result:result];
[self sendLocalNotification:call result:result]; } else if([@"getRegistrationID" isEqualToString:call.method]) {
} else{ [self getRegistrationID:call result:result];
result(FlutterMethodNotImplemented); } else if([@"sendLocalNotification"isEqualToString:call.method]) {
} [self sendLocalNotification:call result:result];
} else{
result(FlutterMethodNotImplemented);
}
} }
- (void)setup:(FlutterMethodCall*)call result:(FlutterResult)result { - (void)setup:(FlutterMethodCall*)call result:(FlutterResult)result {
JPLog(@"setup:"); JPLog(@"setup:");
NSDictionary *arguments = call.arguments; NSDictionary *arguments = call.arguments;
NSNumber *debug = arguments[@"debug"]; NSNumber *debug = arguments[@"debug"];
if ([debug boolValue]) { if ([debug boolValue]) {
[JPUSHService setDebugMode]; [JPUSHService setDebugMode];
} else { } else {
[JPUSHService setLogOFF]; [JPUSHService setLogOFF];
} }
[JPUSHService setupWithOption:_launchNotification [JPUSHService setupWithOption:_launchNotification
appKey:arguments[@"appKey"] appKey:arguments[@"appKey"]
channel:arguments[@"channel"] channel:arguments[@"channel"]
apsForProduction:[arguments[@"production"] boolValue]]; apsForProduction:[arguments[@"production"] boolValue]];
} }
- (void)applyPushAuthority:(FlutterMethodCall*)call result:(FlutterResult)result { - (void)applyPushAuthority:(FlutterMethodCall*)call result:(FlutterResult)result {
JPLog(@"applyPushAuthority:%@",call.arguments); JPLog(@"applyPushAuthority:%@",call.arguments);
notificationTypes = 0; notificationTypes = 0;
NSDictionary *arguments = call.arguments; NSDictionary *arguments = call.arguments;
if ([arguments[@"sound"] boolValue]) { if ([arguments[@"sound"] boolValue]) {
notificationTypes |= JPAuthorizationOptionSound; notificationTypes |= JPAuthorizationOptionSound;
} }
if ([arguments[@"alert"] boolValue]) { if ([arguments[@"alert"] boolValue]) {
notificationTypes |= JPAuthorizationOptionAlert; notificationTypes |= JPAuthorizationOptionAlert;
} }
if ([arguments[@"badge"] boolValue]) { if ([arguments[@"badge"] boolValue]) {
notificationTypes |= JPAuthorizationOptionBadge; notificationTypes |= JPAuthorizationOptionBadge;
} }
JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init]; JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
entity.types = notificationTypes; entity.types = notificationTypes;
[JPUSHService registerForRemoteNotificationConfig:entity delegate:self]; [JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
} }
- (void)setTags:(FlutterMethodCall*)call result:(FlutterResult)result { - (void)setTags:(FlutterMethodCall*)call result:(FlutterResult)result {
JPLog(@"setTags:%@",call.arguments); JPLog(@"setTags:%@",call.arguments);
NSSet *tagSet; NSSet *tagSet;
if (call.arguments != NULL) { if (call.arguments != NULL) {
tagSet = [NSSet setWithArray: call.arguments]; tagSet = [NSSet setWithArray: call.arguments];
}
[JPUSHService setTags:tagSet completion:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) {
if (iResCode == 0) {
result(@{@"tags": [iTags allObjects] ?: @[]});
} else {
NSError *error = [[NSError alloc] initWithDomain:@"JPush.Flutter" code:iResCode userInfo:nil];
result([error flutterError]);
} }
} seq: 0];
[JPUSHService setTags:tagSet completion:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) {
if (iResCode == 0) {
result(@{@"tags": [iTags allObjects] ?: @[]});
} else {
NSError *error = [[NSError alloc] initWithDomain:@"JPush.Flutter" code:iResCode userInfo:nil];
result([error flutterError]);
}
} seq: 0];
} }
- (void)cleanTags:(FlutterMethodCall*)call result:(FlutterResult)result { - (void)cleanTags:(FlutterMethodCall*)call result:(FlutterResult)result {
JPLog(@"cleanTags:"); JPLog(@"cleanTags:");
[JPUSHService cleanTags:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) { [JPUSHService cleanTags:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) {
if (iResCode == 0) { if (iResCode == 0) {
result(@{@"tags": iTags ? [iTags allObjects] : @[]}); result(@{@"tags": iTags ? [iTags allObjects] : @[]});
} else { } else {
NSError *error = [[NSError alloc] initWithDomain:@"JPush.Flutter" code:iResCode userInfo:nil]; NSError *error = [[NSError alloc] initWithDomain:@"JPush.Flutter" code:iResCode userInfo:nil];
result([error flutterError]); result([error flutterError]);
} }
} seq: 0]; } seq: 0];
} }
- (void)addTags:(FlutterMethodCall*)call result:(FlutterResult)result { - (void)addTags:(FlutterMethodCall*)call result:(FlutterResult)result {
JPLog(@"addTags:%@",call.arguments); JPLog(@"addTags:%@",call.arguments);
NSSet *tagSet; NSSet *tagSet;
if (call.arguments != NULL) { if (call.arguments != NULL) {
tagSet = [NSSet setWithArray:call.arguments]; tagSet = [NSSet setWithArray:call.arguments];
}
[JPUSHService addTags:tagSet completion:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) {
if (iResCode == 0) {
result(@{@"tags": [iTags allObjects] ?: @[]});
} else {
NSError *error = [[NSError alloc] initWithDomain:@"JPush.Flutter" code:iResCode userInfo:nil];
result([error flutterError]);
} }
} seq: 0];
[JPUSHService addTags:tagSet completion:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) {
if (iResCode == 0) {
result(@{@"tags": [iTags allObjects] ?: @[]});
} else {
NSError *error = [[NSError alloc] initWithDomain:@"JPush.Flutter" code:iResCode userInfo:nil];
result([error flutterError]);
}
} seq: 0];
} }
- (void)deleteTags:(FlutterMethodCall*)call result:(FlutterResult)result { - (void)deleteTags:(FlutterMethodCall*)call result:(FlutterResult)result {
JPLog(@"deleteTags:%@",call.arguments); JPLog(@"deleteTags:%@",call.arguments);
NSSet *tagSet; NSSet *tagSet;
if (call.arguments != NULL) { if (call.arguments != NULL) {
tagSet = [NSSet setWithArray:call.arguments]; tagSet = [NSSet setWithArray:call.arguments];
}
[JPUSHService deleteTags:tagSet completion:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) {
if (iResCode == 0) {
result(@{@"tags": [iTags allObjects] ?: @[]});
} else {
NSError *error = [[NSError alloc] initWithDomain:@"JPush.Flutter" code:iResCode userInfo:nil];
result([error flutterError]);
} }
} seq: 0];
[JPUSHService deleteTags:tagSet completion:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) {
if (iResCode == 0) {
result(@{@"tags": [iTags allObjects] ?: @[]});
} else {
NSError *error = [[NSError alloc] initWithDomain:@"JPush.Flutter" code:iResCode userInfo:nil];
result([error flutterError]);
}
} seq: 0];
} }
- (void)getAllTags:(FlutterMethodCall*)call result:(FlutterResult)result { - (void)getAllTags:(FlutterMethodCall*)call result:(FlutterResult)result {
JPLog(@"getAllTags:"); JPLog(@"getAllTags:");
[JPUSHService getAllTags:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) { [JPUSHService getAllTags:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) {
if (iResCode == 0) { if (iResCode == 0) {
result(@{@"tags": iTags ? [iTags allObjects] : @[]}); result(@{@"tags": iTags ? [iTags allObjects] : @[]});
} else { } else {
NSError *error = [[NSError alloc] initWithDomain:@"JPush.Flutter" code:iResCode userInfo:nil]; NSError *error = [[NSError alloc] initWithDomain:@"JPush.Flutter" code:iResCode userInfo:nil];
result([error flutterError]); result([error flutterError]);
} }
} seq: 0]; } seq: 0];
} }
- (void)setAlias:(FlutterMethodCall*)call result:(FlutterResult)result { - (void)setAlias:(FlutterMethodCall*)call result:(FlutterResult)result {
JPLog(@"setAlias:%@",call.arguments); JPLog(@"setAlias:%@",call.arguments);
NSString *alias = call.arguments; NSString *alias = call.arguments;
[JPUSHService setAlias:alias completion:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) { [JPUSHService setAlias:alias completion:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) {
if (iResCode == 0) { if (iResCode == 0) {
result(@{@"alias": iAlias ?: @""}); result(@{@"alias": iAlias ?: @""});
} else { } else {
NSError *error = [[NSError alloc] initWithDomain:@"JPush.Flutter" code:iResCode userInfo:nil]; NSError *error = [[NSError alloc] initWithDomain:@"JPush.Flutter" code:iResCode userInfo:nil];
result([error flutterError]); result([error flutterError]);
} }
} seq: 0]; } seq: 0];
} }
- (void)deleteAlias:(FlutterMethodCall*)call result:(FlutterResult)result { - (void)deleteAlias:(FlutterMethodCall*)call result:(FlutterResult)result {
JPLog(@"deleteAlias:%@",call.arguments); JPLog(@"deleteAlias:%@",call.arguments);
[JPUSHService deleteAlias:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) { [JPUSHService deleteAlias:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) {
if (iResCode == 0) { if (iResCode == 0) {
result(@{@"alias": iAlias ?: @""}); result(@{@"alias": iAlias ?: @""});
} else { } else {
NSError *error = [[NSError alloc] initWithDomain:@"JPush.Flutter" code:iResCode userInfo:nil]; NSError *error = [[NSError alloc] initWithDomain:@"JPush.Flutter" code:iResCode userInfo:nil];
result([error flutterError]); result([error flutterError]);
} }
} seq: 0]; } seq: 0];
} }
- (void)setBadge:(FlutterMethodCall*)call result:(FlutterResult)result { - (void)setBadge:(FlutterMethodCall*)call result:(FlutterResult)result {
JPLog(@"setBadge:%@",call.arguments); JPLog(@"setBadge:%@",call.arguments);
NSInteger badge = [call.arguments[@"badge"] integerValue]; NSInteger badge = [call.arguments[@"badge"] integerValue];
if (badge < 0) { if (badge < 0) {
badge = 0; badge = 0;
} }
[[UIApplication sharedApplication] setApplicationIconBadgeNumber: badge]; [[UIApplication sharedApplication] setApplicationIconBadgeNumber: badge];
[JPUSHService setBadge: badge]; [JPUSHService setBadge: badge];
} }
- (void)stopPush:(FlutterMethodCall*)call result:(FlutterResult)result { - (void)stopPush:(FlutterMethodCall*)call result:(FlutterResult)result {
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 {
JPLog(@"getLaunchAppNotification"); JPLog(@"getLaunchAppNotification");
result(_launchNotification == nil ? @{}: _launchNotification); result(_launchNotification == nil ? @{}: _launchNotification);
} }
- (void)getRegistrationID:(FlutterMethodCall*)call result:(FlutterResult)result { - (void)getRegistrationID:(FlutterMethodCall*)call result:(FlutterResult)result {
JPLog(@"getRegistrationID:"); JPLog(@"getRegistrationID:");
#if TARGET_IPHONE_SIMULATOR//模拟器 #if TARGET_IPHONE_SIMULATOR//模拟器
NSLog(@"simulator can not get registrationid"); NSLog(@"simulator can not get registrationid");
result(@""); result(@"");
#elif TARGET_OS_IPHONE//真机 #elif TARGET_OS_IPHONE//真机
if ([JPUSHService registrationID] != nil && ![[JPUSHService registrationID] isEqualToString:@""]) { if ([JPUSHService registrationID] != nil && ![[JPUSHService registrationID] isEqualToString:@""]) {
// 如果已经成功获取 registrationID,从本地获取直接缓存 // 如果已经成功获取 registrationID,从本地获取直接缓存
result([JPUSHService registrationID]); result([JPUSHService registrationID]);
return; return;
} }
if (_isJPushDidLogin) {// 第一次获取未登录情况 if (_isJPushDidLogin) {// 第一次获取未登录情况
result(@[[JPUSHService registrationID]]); result(@[[JPUSHService registrationID]]);
} else { } else {
[getRidResults addObject:result]; [getRidResults addObject:result];
} }
#endif #endif
} }
- (void)sendLocalNotification:(FlutterMethodCall*)call result:(FlutterResult)result { - (void)sendLocalNotification:(FlutterMethodCall*)call result:(FlutterResult)result {
JPLog(@"sendLocalNotification:%@",call.arguments); JPLog(@"sendLocalNotification:%@",call.arguments);
JPushNotificationContent *content = [[JPushNotificationContent alloc] init]; JPushNotificationContent *content = [[JPushNotificationContent alloc] init];
NSDictionary *params = call.arguments; NSDictionary *params = call.arguments;
if (params[@"title"]) { if (params[@"title"]) {
content.title = params[@"title"]; content.title = params[@"title"];
} }
if (params[@"subtitle"] && ![params[@"subtitle"] isEqualToString:@"<null>"]) { if (params[@"subtitle"] && ![params[@"subtitle"] isEqualToString:@"<null>"]) {
content.subtitle = params[@"subtitle"]; content.subtitle = params[@"subtitle"];
} }
if (params[@"content"]) { if (params[@"content"]) {
content.body = params[@"content"]; content.body = params[@"content"];
} }
if (params[@"badge"]) { if (params[@"badge"]) {
content.badge = params[@"badge"]; content.badge = params[@"badge"];
} }
if (params[@"action"] && ![params[@"action"] isEqualToString:@"<null>"]) { if (params[@"action"] && ![params[@"action"] isEqualToString:@"<null>"]) {
content.action = params[@"action"]; content.action = params[@"action"];
} }
if ([params[@"extra"] isKindOfClass:[NSDictionary class]]) { if ([params[@"extra"] isKindOfClass:[NSDictionary class]]) {
content.userInfo = params[@"extra"]; content.userInfo = params[@"extra"];
} }
if (params[@"sound"] && ![params[@"sound"] isEqualToString:@"<null>"]) { if (params[@"sound"] && ![params[@"sound"] isEqualToString:@"<null>"]) {
content.sound = params[@"sound"]; content.sound = params[@"sound"];
}
JPushNotificationTrigger *trigger = [[JPushNotificationTrigger alloc] init];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 10.0) {
if (params[@"fireTime"]) {
NSNumber *date = params[@"fireTime"];
NSTimeInterval currentInterval = [[NSDate date] timeIntervalSince1970];
NSTimeInterval interval = [date doubleValue]/1000 - currentInterval;
interval = interval>0?interval:0;
trigger.timeInterval = interval;
} }
}
JPushNotificationTrigger *trigger = [[JPushNotificationTrigger alloc] init];
else { if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 10.0) {
if (params[@"fireTime"]) { if (params[@"fireTime"]) {
NSNumber *date = params[@"fireTime"]; NSNumber *date = params[@"fireTime"];
trigger.fireDate = [NSDate dateWithTimeIntervalSince1970: [date doubleValue]/1000]; NSTimeInterval currentInterval = [[NSDate date] timeIntervalSince1970];
NSTimeInterval interval = [date doubleValue]/1000 - currentInterval;
interval = interval>0?interval:0;
trigger.timeInterval = interval;
}
} }
}
JPushNotificationRequest *request = [[JPushNotificationRequest alloc] init]; else {
request.content = content; if (params[@"fireTime"]) {
request.trigger = trigger; NSNumber *date = params[@"fireTime"];
trigger.fireDate = [NSDate dateWithTimeIntervalSince1970: [date doubleValue]/1000];
if (params[@"id"]) { }
NSNumber *identify = params[@"id"]; }
request.requestIdentifier = [identify stringValue]; JPushNotificationRequest *request = [[JPushNotificationRequest alloc] init];
} request.content = content;
request.completionHandler = ^(id result) { request.trigger = trigger;
NSLog(@"result");
}; if (params[@"id"]) {
NSNumber *identify = params[@"id"];
[JPUSHService addNotification:request]; request.requestIdentifier = [identify stringValue];
}
result(@[@[]]); request.completionHandler = ^(id result) {
NSLog(@"result");
};
[JPUSHService addNotification:request];
result(@[@[]]);
} }
- (void)dealloc { - (void)dealloc {
_isJPushDidLogin = NO; _isJPushDidLogin = NO;
[[NSNotificationCenter defaultCenter] removeObserver:self]; [[NSNotificationCenter defaultCenter] removeObserver:self];
} }
#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]; _launchNotification = [self jpushFormatAPNSDic:_launchNotification.copy];
_launchNotification = [self jpushFormatAPNSDic:_launchNotification.copy]; }
}
if ([launchOptions valueForKey:UIApplicationLaunchOptionsLocalNotificationKey]) {
if ([launchOptions valueForKey:UIApplicationLaunchOptionsLocalNotificationKey]) { UILocalNotification *localNotification = [launchOptions valueForKey:UIApplicationLaunchOptionsLocalNotificationKey];
UILocalNotification *localNotification = [launchOptions valueForKey:UIApplicationLaunchOptionsLocalNotificationKey]; NSMutableDictionary *localNotificationEvent = @{}.mutableCopy;
NSMutableDictionary *localNotificationEvent = @{}.mutableCopy; localNotificationEvent[@"content"] = localNotification.alertBody;
localNotificationEvent[@"content"] = localNotification.alertBody; localNotificationEvent[@"badge"] = @(localNotification.applicationIconBadgeNumber);
localNotificationEvent[@"badge"] = @(localNotification.applicationIconBadgeNumber); localNotificationEvent[@"extras"] = localNotification.userInfo;
localNotificationEvent[@"extras"] = localNotification.userInfo; localNotificationEvent[@"fireTime"] = [NSNumber numberWithLong:[localNotification.fireDate timeIntervalSince1970] * 1000];
localNotificationEvent[@"fireTime"] = [NSNumber numberWithLong:[localNotification.fireDate timeIntervalSince1970] * 1000]; localNotificationEvent[@"soundName"] = [localNotification.soundName isEqualToString:UILocalNotificationDefaultSoundName] ? @"" : localNotification.soundName;
localNotificationEvent[@"soundName"] = [localNotification.soundName isEqualToString:UILocalNotificationDefaultSoundName] ? @"" : localNotification.soundName;
if (@available(iOS 8.2, *)) {
if (@available(iOS 8.2, *)) { localNotificationEvent[@"title"] = localNotification.alertTitle;
localNotificationEvent[@"title"] = localNotification.alertTitle; }
_launchNotification = localNotificationEvent;
} }
_launchNotification = localNotificationEvent; return YES;
}
return YES;
} }
- (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
didReceiveRemoteNotification:(NSDictionary *)userInfo didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler { fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {
[_channel invokeMethod:@"onReceiveNotification" arguments:userInfo]; [_channel invokeMethod:@"onReceiveNotification" arguments:userInfo];
completionHandler(UIBackgroundFetchResultNoData); completionHandler(UIBackgroundFetchResultNoData);
return YES; return YES;
} }
- (void)application:(UIApplication *)application - (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[JPUSHService registerDeviceToken:deviceToken]; [JPUSHService registerDeviceToken:deviceToken];
} }
- (void)application:(UIApplication *)application - (void)application:(UIApplication *)application
didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings { didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
NSDictionary *settingsDictionary = @{ NSDictionary *settingsDictionary = @{
@"sound" : [NSNumber numberWithBool:notificationSettings.types & UIUserNotificationTypeSound], @"sound" : [NSNumber numberWithBool:notificationSettings.types & UIUserNotificationTypeSound],
@"badge" : [NSNumber numberWithBool:notificationSettings.types & UIUserNotificationTypeBadge], @"badge" : [NSNumber numberWithBool:notificationSettings.types & UIUserNotificationTypeBadge],
@"alert" : [NSNumber numberWithBool:notificationSettings.types & UIUserNotificationTypeAlert], @"alert" : [NSNumber numberWithBool:notificationSettings.types & UIUserNotificationTypeAlert],
}; };
[_channel invokeMethod:@"onIosSettingsRegistered" arguments:settingsDictionary]; [_channel invokeMethod:@"onIosSettingsRegistered" arguments:settingsDictionary];
} }
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler API_AVAILABLE(ios(10.0)){ - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler API_AVAILABLE(ios(10.0)){
NSDictionary * userInfo = notification.request.content.userInfo; NSDictionary * userInfo = notification.request.content.userInfo;
if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) { if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
[JPUSHService handleRemoteNotification:userInfo]; [JPUSHService handleRemoteNotification:userInfo];
[_channel invokeMethod:@"onReceiveNotification" arguments: [self jpushFormatAPNSDic:userInfo]]; [_channel invokeMethod:@"onReceiveNotification" arguments: [self jpushFormatAPNSDic:userInfo]];
} }
completionHandler(notificationTypes); completionHandler(notificationTypes);
} }
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler API_AVAILABLE(ios(10.0)){ - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler API_AVAILABLE(ios(10.0)){
NSDictionary * userInfo = response.notification.request.content.userInfo; NSDictionary * userInfo = response.notification.request.content.userInfo;
if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) { if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
[JPUSHService handleRemoteNotification:userInfo]; [JPUSHService handleRemoteNotification:userInfo];
[_channel invokeMethod:@"onOpenNotification" arguments: [self jpushFormatAPNSDic:userInfo]]; [_channel invokeMethod:@"onOpenNotification" arguments: [self jpushFormatAPNSDic:userInfo]];
} }
completionHandler(); completionHandler();
} }
- (NSMutableDictionary *)jpushFormatAPNSDic:(NSDictionary *)dic { - (NSMutableDictionary *)jpushFormatAPNSDic:(NSDictionary *)dic {
NSMutableDictionary *extras = @{}.mutableCopy; NSMutableDictionary *extras = @{}.mutableCopy;
for (NSString *key in dic) { for (NSString *key in dic) {
if([key isEqualToString:@"_j_business"] || if([key isEqualToString:@"_j_business"] ||
[key isEqualToString:@"_j_msgid"] || [key isEqualToString:@"_j_msgid"] ||
[key isEqualToString:@"_j_uid"] || [key isEqualToString:@"_j_uid"] ||
[key isEqualToString:@"actionIdentifier"] || [key isEqualToString:@"actionIdentifier"] ||
[key isEqualToString:@"aps"]) { [key isEqualToString:@"aps"]) {
continue; continue;
}
extras[key] = dic[key];
} }
extras[key] = dic[key]; NSMutableDictionary *formatDic = dic.mutableCopy;
} formatDic[@"extras"] = extras;
NSMutableDictionary *formatDic = dic.mutableCopy; return formatDic;
formatDic[@"extras"] = extras;
return formatDic;
} }
@end @end

@ -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'
@ -19,5 +19,4 @@ 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,257 +3,281 @@ 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 {
final String flutter_log = "| JPUSH | Flutter | "; final String flutter_log = "| JPUSH | Flutter | ";
factory JPush() => _instance; factory JPush() => _instance;
final MethodChannel _channel; final MethodChannel _channel;
final Platform _platform; final Platform _platform;
@visibleForTesting @visibleForTesting
JPush.private(MethodChannel channel, Platform platform) JPush.private(MethodChannel channel, Platform platform)
: _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; EventHandler _onReceiveMessage;
EventHandler _onReceiveMessage;
void setup({
void setup({ String appKey,
String appKey, bool production,
bool production, String channel = '',
String channel = '', bool debug = false,
bool debug = false, }) {
}) { print(flutter_log + "setup:");
print(flutter_log + "setup:");
_channel.invokeMethod('setup', {
_channel.invokeMethod('setup', { 'appKey': appKey, 'channel': channel, 'production': production, 'debug': debug}); 'appKey': appKey,
} 'channel': channel,
/// 'production': production,
/// JPush () 'debug': debug
/// });
void addEventHandler({ }
EventHandler onReceiveNotification,
EventHandler onOpenNotification, ///
EventHandler onReceiveMessage, /// JPush ()
}) { ///
print(flutter_log + "addEventHandler:"); void addEventHandler({
EventHandler onReceiveNotification,
_onReceiveNotification = onReceiveNotification; EventHandler onOpenNotification,
_onOpenNotification = onOpenNotification; EventHandler onReceiveMessage,
_onReceiveMessage = onReceiveMessage; }) {
_channel.setMethodCallHandler(_handleMethod); print(flutter_log + "addEventHandler:");
_onReceiveNotification = onReceiveNotification;
_onOpenNotification = onOpenNotification;
_onReceiveMessage = onReceiveMessage;
_channel.setMethodCallHandler(_handleMethod);
}
Future<Null> _handleMethod(MethodCall call) async {
print(flutter_log + "_handleMethod:");
switch (call.method) {
case "onReceiveNotification":
return _onReceiveNotification(call.arguments.cast<String, dynamic>());
case "onOpenNotification":
return _onOpenNotification(call.arguments.cast<String, dynamic>());
case "onReceiveMessage":
return _onReceiveMessage(call.arguments.cast<String, dynamic>());
default:
throw new UnsupportedError("Unrecognized Event");
} }
}
///
///
///
void applyPushAuthority(
[NotificationSettingsIOS iosSettings = const NotificationSettingsIOS()]) {
print(flutter_log + "applyPushAuthority:");
Future<Null> _handleMethod(MethodCall call) async { if (!_platform.isIOS) {
print(flutter_log + "_handleMethod:"); return;
switch (call.method) {
case "onReceiveNotification":
return _onReceiveNotification(call.arguments.cast<String, dynamic>());
case "onOpenNotification":
return _onOpenNotification(call.arguments.cast<String, dynamic>());
case "onReceiveMessage":
return _onReceiveMessage(call.arguments.cast<String, dynamic>());
default:
throw new UnsupportedError("Unrecognized Event");
}
} }
/// _channel.invokeMethod('applyPushAuthority', iosSettings.toMap());
/// }
///
void applyPushAuthority([NotificationSettingsIOS iosSettings = const NotificationSettingsIOS()]) {
print(flutter_log + "applyPushAuthority:");
if (!_platform.isIOS) { ///
return; /// Tag tags
} ///
/// @param {Array} params = [String]
/// @param {Function} success = ({"tags":[String]}) => { }
/// @param {Function} fail = ({"errorCode":int}) => { }
///
Future<Map<dynamic, dynamic>> setTags(List<String> tags) async {
print(flutter_log + "setTags:");
final Map<dynamic, dynamic> result =
await _channel.invokeMethod('setTags', tags);
return result;
}
_channel.invokeMethod('applyPushAuthority', iosSettings.toMap()); ///
} /// tags
///
/// /// @param {Function} success = ({"tags":[String]}) => { }
/// Tag tags /// @param {Function} fail = ({"errorCode":int}) => { }
/// ///
/// @param {Array} params = [String] Future<Map<dynamic, dynamic>> cleanTags() async {
/// @param {Function} success = ({"tags":[String]}) => { } print(flutter_log + "cleanTags:");
/// @param {Function} fail = ({"errorCode":int}) => { }
/// final Map<dynamic, dynamic> result =
Future<Map<dynamic, dynamic>> setTags(List<String> tags) async { await _channel.invokeMethod('cleanTags');
print(flutter_log + "setTags:"); return result;
}
final Map<dynamic, dynamic> result = await _channel.invokeMethod('setTags', tags);
return result;
}
/// ///
/// tags /// tags tags
/// ///
/// @param {Function} success = ({"tags":[String]}) => { } /// @param {Array} tags = [String]
/// @param {Function} fail = ({"errorCode":int}) => { } /// @param {Function} success = ({"tags":[String]}) => { }
/// /// @param {Function} fail = ({"errorCode":int}) => { }
Future<Map<dynamic, dynamic>> cleanTags() async { ///
print(flutter_log + "cleanTags:");
final Map<dynamic, dynamic> result = await _channel.invokeMethod('cleanTags');
return result;
}
///
/// tags tags
///
/// @param {Array} tags = [String]
/// @param {Function} success = ({"tags":[String]}) => { }
/// @param {Function} fail = ({"errorCode":int}) => { }
///
Future<Map<dynamic, dynamic>> addTags(List<String> tags) async {
print(flutter_log + "addTags:");
final Map<dynamic, dynamic> result = await _channel.invokeMethod('addTags', tags);
return result;
}
///
/// tags
///
/// @param {Array} tags = [String]
/// @param {Function} success = ({"tags":[String]}) => { }
/// @param {Function} fail = ({"errorCode":int}) => { }
///
Future<Map<dynamic, dynamic>> deleteTags(List<String> tags) async {
print(flutter_log + "deleteTags:");
final Map<dynamic, dynamic> result = await _channel.invokeMethod('deleteTags', tags);
return result;
}
///
/// tags
///
/// @param {Function} success = ({"tags":[String]}) => { }
/// @param {Function} fail = ({"errorCode":int}) => { }
///
Future<Map<dynamic, dynamic>> getAllTags() async {
print(flutter_log + "getAllTags:");
final Map<dynamic, dynamic> result = await _channel.invokeMethod('getAllTags');
return result;
}
///
/// alias.
///
/// @param {String} alias
///
/// @param {Function} success = ({"alias":String}) => { }
/// @param {Function} fail = ({"errorCode":int}) => { }
///
Future<Map<dynamic, dynamic>> setAlias(String alias) async {
print(flutter_log + "setAlias:");
final Map<dynamic, dynamic> result = await _channel.invokeMethod('setAlias', alias);
return result;
}
/// Future<Map<dynamic, dynamic>> addTags(List<String> tags) async {
/// alias print(flutter_log + "addTags:");
///
/// @param {Function} success = ({"alias":String}) => { }
/// @param {Function} fail = ({"errorCode":int}) => { }
///
Future<Map<dynamic, dynamic>> deleteAlias() async {
print(flutter_log + "deleteAlias:");
final Map<dynamic, dynamic> result = await _channel.invokeMethod('deleteAlias');
return result;
}
/// final Map<dynamic, dynamic> result =
/// Badge await _channel.invokeMethod('addTags', tags);
/// return result;
/// @param {Int} badge }
///
/// Android
///
Future setBadge(int badge) async {
print(flutter_log + "setBadge:");
await _channel.invokeMethod('setBadge', {"badge":badge});
}
/// ///
/// resumePush /// tags
/// ///
Future stopPush() async { /// @param {Array} tags = [String]
print(flutter_log + "stopPush:"); /// @param {Function} success = ({"tags":[String]}) => { }
/// @param {Function} fail = ({"errorCode":int}) => { }
///
Future<Map<dynamic, dynamic>> deleteTags(List<String> tags) async {
print(flutter_log + "deleteTags:");
final Map<dynamic, dynamic> result =
await _channel.invokeMethod('deleteTags', tags);
return result;
}
await _channel.invokeMethod('stopPush'); ///
} /// tags
///
/// /// @param {Function} success = ({"tags":[String]}) => { }
/// /// @param {Function} fail = ({"errorCode":int}) => { }
/// ///
Future resumePush() async { Future<Map<dynamic, dynamic>> getAllTags() async {
print(flutter_log + "resumePush:"); print(flutter_log + "getAllTags:");
await _channel.invokeMethod('resumePush'); final Map<dynamic, dynamic> result =
} await _channel.invokeMethod('getAllTags');
return result;
/// }
///
///
Future clearAllNotifications() async {
print(flutter_log + "clearAllNotifications:");
await _channel.invokeMethod('clearAllNotifications');
}
///
/// iOS Only
/// notification notification
/// notification remoteNotification localNotification
/// icon notification @{}
/// @param {Function} callback = (Object) => {}
///
Future<Map<dynamic, dynamic>> getLaunchAppNotification() async {
print(flutter_log + "getLaunchAppNotification:");
final Map<dynamic, dynamic> result = await _channel.invokeMethod('getLaunchAppNotification');
return result;
}
/// ///
/// RegistrationId, JPush RegistrationId /// alias.
/// ///
/// @param {Function} callback = (String) => {} /// @param {String} alias
/// ///
Future<String> getRegistrationID() async { /// @param {Function} success = ({"alias":String}) => { }
print(flutter_log + "getRegistrationID:"); /// @param {Function} fail = ({"errorCode":int}) => { }
///
Future<Map<dynamic, dynamic>> setAlias(String alias) async {
print(flutter_log + "setAlias:");
final Map<dynamic, dynamic> result =
await _channel.invokeMethod('setAlias', alias);
return result;
}
final String rid = await _channel.invokeMethod('getRegistrationID'); ///
return rid; /// alias
} ///
/// @param {Function} success = ({"alias":String}) => { }
/// @param {Function} fail = ({"errorCode":int}) => { }
///
Future<Map<dynamic, dynamic>> deleteAlias() async {
print(flutter_log + "deleteAlias:");
final Map<dynamic, dynamic> result =
await _channel.invokeMethod('deleteAlias');
return result;
}
///
/// Badge
///
/// @param {Int} badge
///
/// Android
///
Future setBadge(int badge) async {
print(flutter_log + "setBadge:");
await _channel.invokeMethod('setBadge', {"badge": badge});
}
///
/// resumePush
///
Future stopPush() async {
print(flutter_log + "stopPush:");
/// await _channel.invokeMethod('stopPush');
/// }
/// @param {Notification} notification
/// ///
Future<String> sendLocalNotification(LocalNotification notification) async { ///
print(flutter_log + "sendLocalNotification:"); ///
Future resumePush() async {
print(flutter_log + "resumePush:");
await _channel.invokeMethod('resumePush');
}
///
///
///
Future clearAllNotifications() async {
print(flutter_log + "clearAllNotifications:");
await _channel.invokeMethod('clearAllNotifications');
}
///
///
/// @param notificationId idLocalNotification id
///
void clearNotification({@required int notificationId}) {
print(flutter_log + "clearNotification:");
_channel.invokeListMethod("clearNotification",notificationId);
}
///
/// iOS Only
/// notification notification
/// notification remoteNotification localNotification
/// icon notification @{}
/// @param {Function} callback = (Object) => {}
///
Future<Map<dynamic, dynamic>> getLaunchAppNotification() async {
print(flutter_log + "getLaunchAppNotification:");
final Map<dynamic, dynamic> result =
await _channel.invokeMethod('getLaunchAppNotification');
return result;
}
await _channel.invokeMethod('sendLocalNotification', notification.toMap()); ///
/// RegistrationId, JPush RegistrationId
///
/// @param {Function} callback = (String) => {}
///
Future<String> getRegistrationID() async {
print(flutter_log + "getRegistrationID:");
final String rid = await _channel.invokeMethod('getRegistrationID');
return rid;
}
///
///
/// @param {Notification} notification
///
Future<String> sendLocalNotification(LocalNotification notification) async {
print(flutter_log + "sendLocalNotification:");
await _channel.invokeMethod('sendLocalNotification', notification.toMap());
return notification.toMap().toString(); return notification.toMap().toString();
} }
} }
@ -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,54 +297,47 @@ 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,
this.buildId, this.buildId,
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);
Map<String, dynamic> toMap() { Map<String, dynamic> toMap() {
return <String, dynamic>{ return <String, dynamic>{
'id': id, 'id': id,
'title': title, 'title': title,
'content': content, 'content': content,
'fireTime': fireTime.millisecondsSinceEpoch, 'fireTime': fireTime.millisecondsSinceEpoch,
@ -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