diff --git a/.dart_tool/package_config.json b/.dart_tool/package_config.json new file mode 100644 index 0000000..3193de1 --- /dev/null +++ b/.dart_tool/package_config.json @@ -0,0 +1,338 @@ +{ + "configVersion": 2, + "packages": [ + { + "name": "analyzer", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/analyzer-0.37.0", + "packageUri": "lib/", + "languageVersion": "2.2" + }, + { + "name": "args", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/args-1.5.2", + "packageUri": "lib/", + "languageVersion": "2.0" + }, + { + "name": "async", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/async-2.3.0", + "packageUri": "lib/", + "languageVersion": "2.0" + }, + { + "name": "boolean_selector", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/boolean_selector-1.0.5", + "packageUri": "lib/", + "languageVersion": "2.0" + }, + { + "name": "charcode", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/charcode-1.1.2", + "packageUri": "lib/", + "languageVersion": "1.0" + }, + { + "name": "collection", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/collection-1.14.11", + "packageUri": "lib/", + "languageVersion": "2.0" + }, + { + "name": "convert", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/convert-2.1.1", + "packageUri": "lib/", + "languageVersion": "1.17" + }, + { + "name": "crypto", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/crypto-2.0.6", + "packageUri": "lib/", + "languageVersion": "2.0" + }, + { + "name": "csslib", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/csslib-0.16.1", + "packageUri": "lib/", + "languageVersion": "2.1" + }, + { + "name": "flutter", + "rootUri": "file:///Applications/flutter/packages/flutter", + "packageUri": "lib/", + "languageVersion": "2.2" + }, + { + "name": "front_end", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/front_end-0.1.20", + "packageUri": "lib/", + "languageVersion": "2.1" + }, + { + "name": "glob", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/glob-1.1.7", + "packageUri": "lib/", + "languageVersion": "1.23" + }, + { + "name": "html", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/html-0.14.0+2", + "packageUri": "lib/", + "languageVersion": "2.0" + }, + { + "name": "http", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/http-0.12.0+2", + "packageUri": "lib/", + "languageVersion": "2.0" + }, + { + "name": "http_multi_server", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/http_multi_server-2.1.0", + "packageUri": "lib/", + "languageVersion": "2.1" + }, + { + "name": "http_parser", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/http_parser-3.1.3", + "packageUri": "lib/", + "languageVersion": "2.0" + }, + { + "name": "io", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/io-0.3.3", + "packageUri": "lib/", + "languageVersion": "2.0" + }, + { + "name": "js", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/js-0.6.1+1", + "packageUri": "lib/", + "languageVersion": "1.19" + }, + { + "name": "kernel", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/kernel-0.3.20", + "packageUri": "lib/", + "languageVersion": "2.0" + }, + { + "name": "matcher", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/matcher-0.12.5", + "packageUri": "lib/", + "languageVersion": "2.0" + }, + { + "name": "meta", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/meta-1.1.8", + "packageUri": "lib/", + "languageVersion": "1.12" + }, + { + "name": "mime", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/mime-0.9.6+3", + "packageUri": "lib/", + "languageVersion": "2.0" + }, + { + "name": "mockito", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/mockito-3.0.2", + "packageUri": "lib/", + "languageVersion": "2.0" + }, + { + "name": "multi_server_socket", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/multi_server_socket-1.0.2", + "packageUri": "lib/", + "languageVersion": "2.0" + }, + { + "name": "node_preamble", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/node_preamble-1.4.5", + "packageUri": "lib/", + "languageVersion": "1.24" + }, + { + "name": "package_config", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/package_config-1.0.5", + "packageUri": "lib/", + "languageVersion": "2.0" + }, + { + "name": "package_resolver", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/package_resolver-1.0.10", + "packageUri": "lib/", + "languageVersion": "2.1" + }, + { + "name": "path", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/path-1.6.2", + "packageUri": "lib/", + "languageVersion": "2.0" + }, + { + "name": "pedantic", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/pedantic-1.8.0+1", + "packageUri": "lib/", + "languageVersion": "2.1" + }, + { + "name": "platform", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/platform-2.2.0", + "packageUri": "lib/", + "languageVersion": "1.24" + }, + { + "name": "pool", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/pool-1.4.0", + "packageUri": "lib/", + "languageVersion": "2.0" + }, + { + "name": "pub_semver", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/pub_semver-1.4.2", + "packageUri": "lib/", + "languageVersion": "1.0" + }, + { + "name": "shelf", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/shelf-0.7.5", + "packageUri": "lib/", + "languageVersion": "2.0" + }, + { + "name": "shelf_packages_handler", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/shelf_packages_handler-1.0.4", + "packageUri": "lib/", + "languageVersion": "1.22" + }, + { + "name": "shelf_static", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/shelf_static-0.2.8", + "packageUri": "lib/", + "languageVersion": "2.0" + }, + { + "name": "shelf_web_socket", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/shelf_web_socket-0.2.3", + "packageUri": "lib/", + "languageVersion": "2.0" + }, + { + "name": "sky_engine", + "rootUri": "file:///Applications/flutter/bin/cache/pkg/sky_engine", + "packageUri": "lib/", + "languageVersion": "1.11" + }, + { + "name": "source_map_stack_trace", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/source_map_stack_trace-1.1.5", + "packageUri": "lib/", + "languageVersion": "1.8" + }, + { + "name": "source_maps", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/source_maps-0.10.8", + "packageUri": "lib/", + "languageVersion": "2.0" + }, + { + "name": "source_span", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/source_span-1.5.5", + "packageUri": "lib/", + "languageVersion": "1.8" + }, + { + "name": "stack_trace", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/stack_trace-1.9.3", + "packageUri": "lib/", + "languageVersion": "1.23" + }, + { + "name": "stream_channel", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/stream_channel-2.0.0", + "packageUri": "lib/", + "languageVersion": "2.0" + }, + { + "name": "stream_transform", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/stream_transform-0.0.19", + "packageUri": "lib/", + "languageVersion": "2.2" + }, + { + "name": "string_scanner", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/string_scanner-1.0.4", + "packageUri": "lib/", + "languageVersion": "1.8" + }, + { + "name": "term_glyph", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/term_glyph-1.1.0", + "packageUri": "lib/", + "languageVersion": "1.8" + }, + { + "name": "test", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/test-1.6.5", + "packageUri": "lib/", + "languageVersion": "2.2" + }, + { + "name": "test_api", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/test_api-0.2.6", + "packageUri": "lib/", + "languageVersion": "2.1" + }, + { + "name": "test_core", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/test_core-0.2.7", + "packageUri": "lib/", + "languageVersion": "2.1" + }, + { + "name": "typed_data", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/typed_data-1.1.6", + "packageUri": "lib/", + "languageVersion": "2.0" + }, + { + "name": "vector_math", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/vector_math-2.0.8", + "packageUri": "lib/", + "languageVersion": "2.0" + }, + { + "name": "vm_service_lib", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/vm_service_lib-3.22.2", + "packageUri": "lib/", + "languageVersion": "2.0" + }, + { + "name": "watcher", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/watcher-0.9.7+12", + "packageUri": "lib/", + "languageVersion": "2.0" + }, + { + "name": "web_socket_channel", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/web_socket_channel-1.0.14", + "packageUri": "lib/", + "languageVersion": "2.0" + }, + { + "name": "yaml", + "rootUri": "file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/yaml-2.1.16", + "packageUri": "lib/", + "languageVersion": "2.0" + }, + { + "name": "jpush_flutter", + "rootUri": "../", + "packageUri": "lib/", + "languageVersion": "2.0" + } + ], + "generated": "2019-12-31T07:03:35.878530Z", + "generator": "pub", + "generatorVersion": "2.7.0" +} diff --git a/.packages b/.packages index 496e7ef..54e8ec8 100644 --- a/.packages +++ b/.packages @@ -1,4 +1,4 @@ -# Generated by pub on 2019-11-19 13:53:32.095797. +# Generated by pub on 2019-12-31 15:03:35.849743. 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/ 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/ 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/ -meta:file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/meta-1.1.7/lib/ +meta:file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/meta-1.1.8/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/ multi_server_socket:file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/multi_server_socket-1.0.2/lib/ diff --git a/CHANGELOG.md b/CHANGELOG.md index bf98e52..1509a00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 0.5.0 ++ 适配最新版本 JPush SDK ++ 适配新版 SDK 的新功能接口 ## 0.3.0 + 新增:清除通知栏单条通知方法 + 修复:点击通知栏无法获取消息问题 diff --git a/README.md b/README.md index 325e601..a1efaba 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ ```yaml dependencies: - jpush_flutter: 0.3.0 + jpush_flutter: 0.5.0 //github dependencies: diff --git a/android/build.gradle b/android/build.gradle index 4edd23e..af84540 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -34,8 +34,8 @@ android { } dependencies { - implementation 'cn.jiguang.sdk:jpush:3.4.0' - implementation 'cn.jiguang.sdk:jcore:2.1.6' + implementation 'cn.jiguang.sdk:jpush:3.5.4' + implementation 'cn.jiguang.sdk:jcore:2.2.4' // implementation 'com.android.support:appcompat-v7:28.+' compileOnly files('libs/flutter.jar') diff --git a/android/src/main/java/com/jiguang/jpush/JPushEventReceiver.java b/android/src/main/java/com/jiguang/jpush/JPushEventReceiver.java index 5bdbe3d..8e41aa0 100644 --- a/android/src/main/java/com/jiguang/jpush/JPushEventReceiver.java +++ b/android/src/main/java/com/jiguang/jpush/JPushEventReceiver.java @@ -14,6 +14,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import cn.jpush.android.api.JPushInterface; import cn.jpush.android.api.JPushMessage; import cn.jpush.android.service.JPushMessageReceiver; import io.flutter.plugin.common.MethodChannel.Result; @@ -130,4 +131,14 @@ public class JPushEventReceiver extends JPushMessageReceiver { } }); } + + @Override + public void onNotificationSettingsCheck(Context context, boolean isOn, int source) { + super.onNotificationSettingsCheck(context, isOn, source); + + + HashMap map = new HashMap(); + map.put("isEnabled",isOn); + JPushPlugin.instance.runMainThread(map,null,"onReceiveNotificationAuthorization"); + } } diff --git a/android/src/main/java/com/jiguang/jpush/JPushPlugin.java b/android/src/main/java/com/jiguang/jpush/JPushPlugin.java index d4643d2..8ff332a 100644 --- a/android/src/main/java/com/jiguang/jpush/JPushPlugin.java +++ b/android/src/main/java/com/jiguang/jpush/JPushPlugin.java @@ -3,6 +3,8 @@ package com.jiguang.jpush; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.os.Handler; +import android.os.Looper; import android.util.Log; import org.json.JSONObject; @@ -106,12 +108,32 @@ public class JPushPlugin implements MethodCallHandler { sendLocalNotification(call, result); } else if (call.method.equals("setBadge")) { setBadge(call, result); + } else if (call.method.equals("isNotificationEnabled")) { + isNotificationEnabled(call, result); + } else if (call.method.equals("openSettingsForNotification")) { + openSettingsForNotification(call, result); } else { result.notImplemented(); } } + // 主线程再返回数据 + public void runMainThread(final Map map, final Result result, final String method) { + Log.d(TAG,"runMainThread:" + "map = " + map + ",method =" + method); + android.os.Handler handler = new Handler(Looper.getMainLooper()); + handler.post(new Runnable() { + @Override + public void run() { + if (result == null && method != null){ + channel.invokeMethod(method,map); + } else { + result.success(map); + } + } + }); + } + public void setup(MethodCall call, Result result) { Log.d(TAG,"setup :" + call.arguments); @@ -298,6 +320,24 @@ public class JPushPlugin implements MethodCallHandler { } } + /// 检查当前应用的通知开关是否开启 + private void isNotificationEnabled(MethodCall call, Result result) { + Log.d(TAG,"isNotificationEnabled: "); + int isEnabled = JPushInterface.isNotificationEnabled(registrar.context()); + //1表示开启,0表示关闭,-1表示检测失败 + HashMap map = new HashMap(); + map.put("isEnabled",isEnabled==1?true:false); + + runMainThread(map,result,null); + } + + private void openSettingsForNotification(MethodCall call, Result result) { + Log.d(TAG,"openSettingsForNotification: " ); + + JPushInterface.goToAppNotificationSettings(registrar.context()); + + } + /** * 接收自定义消息,通知,通知点击事件等事件的广播 * 文档链接:http://docs.jiguang.cn/client/android_api/ @@ -310,6 +350,8 @@ public class JPushPlugin implements MethodCallHandler { public JPushReceiver() { } + + @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); diff --git a/example/.flutter-plugins-dependencies b/example/.flutter-plugins-dependencies new file mode 100644 index 0000000..564fcf4 --- /dev/null +++ b/example/.flutter-plugins-dependencies @@ -0,0 +1 @@ +{"_info":"// This is a generated file; do not edit or check into version control.","dependencyGraph":[{"name":"jpush_flutter","dependencies":[]}]} \ No newline at end of file diff --git a/example/android/gradle.properties b/example/android/gradle.properties index 353176d..c1c352e 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -18,3 +18,4 @@ org.gradle.jvmargs=-Xmx1536M #systemProp.https.proxyHost=127.0.0.1 #systemProp.http.proxyPort=1086 +android.enableR8=true diff --git a/example/ios/Flutter/Flutter.podspec b/example/ios/Flutter/Flutter.podspec new file mode 100644 index 0000000..5ca3041 --- /dev/null +++ b/example/ios/Flutter/Flutter.podspec @@ -0,0 +1,18 @@ +# +# NOTE: This podspec is NOT to be published. It is only used as a local source! +# + +Pod::Spec.new do |s| + s.name = 'Flutter' + s.version = '1.0.0' + s.summary = 'High-performance, high-fidelity mobile apps.' + s.description = <<-DESC +Flutter provides an easy and productive way to build and deploy high-performance mobile apps for Android and iOS. + DESC + s.homepage = 'https://flutter.io' + s.license = { :type => 'MIT' } + s.author = { 'Flutter Dev Team' => 'flutter-dev@googlegroups.com' } + s.source = { :git => 'https://github.com/flutter/engine', :tag => s.version.to_s } + s.ios.deployment_target = '8.0' + s.vendored_frameworks = 'Flutter.framework' +end diff --git a/example/ios/Flutter/flutter_export_environment.sh b/example/ios/Flutter/flutter_export_environment.sh index 91af1a2..d7849cc 100755 --- a/example/ios/Flutter/flutter_export_environment.sh +++ b/example/ios/Flutter/flutter_export_environment.sh @@ -2,9 +2,10 @@ # 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_TARGET=/Users/raoxudong/JPush/jpush-github/jpush-flutter-plugin/example/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" +export "TRACK_WIDGET_CREATION=true" diff --git a/example/lib/main.dart b/example/lib/main.dart index 515b41f..8705650 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -24,45 +24,42 @@ class _MyAppState extends State { Future initPlatformState() async { String platformVersion; - try { jpush.addEventHandler( - onReceiveNotification: (Map message) async { - print("flutter onReceiveNotification: $message"); - setState(() { - debugLable = "flutter onReceiveNotification: $message"; - }); - }, - onOpenNotification: (Map message) async { - print("flutter onOpenNotification: $message"); - setState(() { - debugLable = "flutter onOpenNotification: $message"; - }); - }, - onReceiveMessage: (Map message) async { - print("flutter onReceiveMessage: $message"); - setState(() { - debugLable = "flutter onReceiveMessage: $message"; - }); - }, - ); - + onReceiveNotification: (Map message) async { + print("flutter onReceiveNotification: $message"); + setState(() { + debugLable = "flutter onReceiveNotification: $message"; + }); + }, onOpenNotification: (Map message) async { + print("flutter onOpenNotification: $message"); + setState(() { + debugLable = "flutter onOpenNotification: $message"; + }); + }, onReceiveMessage: (Map message) async { + print("flutter onReceiveMessage: $message"); + setState(() { + debugLable = "flutter onReceiveMessage: $message"; + }); + }, onReceiveNotificationAuthorization: + (Map message) async { + print("flutter onReceiveNotificationAuthorization: $message"); + setState(() { + debugLable = "flutter onReceiveNotificationAuthorization: $message"; + }); + }); } on PlatformException { platformVersion = 'Failed to get platform version.'; } - jpush.setup( - appKey: "你自己应用的 AppKey", + appKey: "e58a32cb3e4469ebf31867e5", //你自己应用的 AppKey channel: "theChannel", production: false, debug: true, - ); - jpush.applyPushAuthority(new NotificationSettingsIOS( - sound: true, - alert: true, - badge: 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) { @@ -72,7 +69,6 @@ class _MyAppState extends State { }); }); - // If the widget was removed from the tree while the asynchronous platform // message was in flight, we want to discard the reply rather than calling // setState to update our non-existent appearance. @@ -83,8 +79,6 @@ class _MyAppState extends State { }); } - - // 编写视图 @override Widget build(BuildContext context) { @@ -94,201 +88,245 @@ class _MyAppState extends State { title: const Text('Plugin example app'), ), body: new Center( - child: new Column( - children:[ - new Text('result: $debugLable\n'), - new Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - new Text(" "), - new CustomButton(title: "sendLocalNotification", onPressed: (){ - // 三秒后出发本地推送 - var fireDate = DateTime.fromMillisecondsSinceEpoch(DateTime.now().millisecondsSinceEpoch + 3000); - var localNotification = LocalNotification( - id: 234, - title: 'fadsfa', - buildId: 1, - content: 'fdas', - fireTime: fireDate, - subtitle: 'fasf', - badge: 5, - extra: {"fa": "0"} - ); - jpush.sendLocalNotification(localNotification).then((res) { - setState(() { - debugLable = res; - }); - }); - }), - new Text(" "), - new CustomButton(title: "getLaunchAppNotification", onPressed: (){ - jpush.getLaunchAppNotification().then((map) { - setState(() { - debugLable = "getLaunchAppNotification success: $map"; - }); - }) - .catchError((error) { - setState(() { - debugLable = "getLaunchAppNotification error: $error"; + child: new Column(children: [ + Container( + margin: EdgeInsets.fromLTRB(10, 10, 10, 10), + color: Colors.brown, + child: Text(debugLable), + width: 350, + height: 100, + ), + new Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + new Text(" "), + new CustomButton( + title: "发本地推送", + onPressed: () { + // 三秒后出发本地推送 + var fireDate = DateTime.fromMillisecondsSinceEpoch( + DateTime.now().millisecondsSinceEpoch + 3000); + var localNotification = LocalNotification( + id: 234, + title: 'fadsfa', + buildId: 1, + content: 'fdas', + fireTime: fireDate, + subtitle: 'fasf', + badge: 5, + extra: {"fa": "0"}); + jpush + .sendLocalNotification(localNotification) + .then((res) { + setState(() { + debugLable = res; + }); }); - }); - }), - ]), - new Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - new Text(" "), - new CustomButton(title: "setTags", onPressed: (){ - jpush.setTags(["lala","haha"]).then((map) { - var tags = map['tags']; - setState(() { - debugLable = "set tags success: $map $tags"; + }), + new Text(" "), + new CustomButton( + title: "getLaunchAppNotification", + onPressed: () { + jpush.getLaunchAppNotification().then((map) { + setState(() { + debugLable = "getLaunchAppNotification success: $map"; + }); + }).catchError((error) { + setState(() { + debugLable = "getLaunchAppNotification error: $error"; + }); }); - }) - .catchError((error) { - setState(() { - debugLable = "set tags error: $error"; + }), + ]), + new Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + new Text(" "), + new CustomButton( + title: "setTags", + onPressed: () { + jpush.setTags(["lala", "haha"]).then((map) { + var tags = map['tags']; + setState(() { + debugLable = "set tags success: $map $tags"; + }); + }).catchError((error) { + setState(() { + debugLable = "set tags error: $error"; + }); }); - }) ; - }), - new Text(" "), - new CustomButton(title: "addTags", onPressed: (){ - jpush.addTags(["lala","haha"]).then((map) { - var tags = map['tags']; - setState(() { - debugLable = "addTags success: $map $tags"; + }), + new Text(" "), + new CustomButton( + title: "addTags", + onPressed: () { + jpush.addTags(["lala", "haha"]).then((map) { + var tags = map['tags']; + setState(() { + debugLable = "addTags success: $map $tags"; + }); + }).catchError((error) { + setState(() { + debugLable = "addTags error: $error"; + }); }); - }).catchError((error) { - setState(() { - debugLable = "addTags error: $error"; + }), + new Text(" "), + new CustomButton( + title: "deleteTags", + onPressed: () { + jpush.deleteTags(["lala", "haha"]).then((map) { + var tags = map['tags']; + setState(() { + debugLable = "deleteTags success: $map $tags"; + }); + }).catchError((error) { + setState(() { + debugLable = "deleteTags error: $error"; + }); }); - }) ; - }), - new Text(" "), - new CustomButton(title: "deleteTags", onPressed: (){ - jpush.deleteTags(["lala","haha"]).then((map) { - var tags = map['tags']; - setState(() { - debugLable = "deleteTags success: $map $tags"; + }), + ]), + new Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + new Text(" "), + new CustomButton( + title: "getAllTags", + onPressed: () { + jpush.getAllTags().then((map) { + setState(() { + debugLable = "getAllTags success: $map"; + }); + }).catchError((error) { + setState(() { + debugLable = "getAllTags error: $error"; + }); }); - }) - .catchError((error) { - setState(() { - debugLable = "deleteTags error: $error"; + }), + new Text(" "), + new CustomButton( + title: "cleanTags", + 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: [ - new Text(" "), - new CustomButton(title: "getAllTags", onPressed: (){ - jpush.getAllTags().then((map) { - setState(() { - debugLable = "getAllTags success: $map"; + }), + ]), + new Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + new Text(" "), + new CustomButton( + title: "setAlias", + onPressed: () { + jpush.setAlias("thealias11").then((map) { + setState(() { + debugLable = "setAlias success: $map"; + }); + }).catchError((error) { + setState(() { + debugLable = "setAlias error: $error"; + }); }); - }) - .catchError((error) { - setState(() { - debugLable = "getAllTags 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 Text(" "), - new CustomButton(title: "cleanTags", 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: [ - new Text(" "), - new CustomButton(title: "setAlias", onPressed: (){ - jpush.setAlias("thealias11").then((map) { - setState(() { - debugLable = "setAlias success: $map"; - }); - }) - .catchError((error) { - setState(() { - debugLable = "setAlias 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 Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - new Text(" "), - new CustomButton(title: "stopPush",onPressed: (){ + }), + ]), + new Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + new Text(" "), + new CustomButton( + title: "stopPush", + onPressed: () { jpush.stopPush(); }), - new Text(" "), - new CustomButton(title: "resumePush", onPressed: (){ + new Text(" "), + new CustomButton( + title: "resumePush", + onPressed: () { jpush.resumePush(); }), - ], - ), - new Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - new Text(" "), - new CustomButton(title: "clearAllNotifications",onPressed: (){ + ], + ), + new Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + new Text(" "), + new CustomButton( + title: "clearAllNotifications", + onPressed: () { jpush.clearAllNotifications(); }), - new Text(" "), - new CustomButton(title: "setBadge", onPressed: (){ + new Text(" "), + new CustomButton( + title: "setBadge", + onPressed: () { jpush.setBadge(66).then((map) { setState(() { debugLable = "setBadge success: $map"; }); - }) - .catchError((error) { + }).catchError((error) { setState(() { debugLable = "setBadge error: $error"; }); }); }), - ], - ), - ] - ) - ), + ], + ), + new Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + new Text(" "), + new CustomButton( + title: "通知授权是否打开", + onPressed: () { + jpush.isNotificationEnabled().then((bool value) { + setState(() { + debugLable = "通知授权是否打开: $value"; + }); + }).catchError((onError) { + setState(() { + debugLable = "通知授权是否打开: ${onError.toString()}"; + }); + }); + }), + new Text(" "), + new CustomButton( + title: "打开系统设置", + onPressed: () { + jpush.openSettingsForNotification(); + }), + ], + ), + ])), ), ); } } + /// 封装控件 class CustomButton extends StatelessWidget { - final VoidCallback onPressed; final String title; @@ -306,4 +344,4 @@ class CustomButton extends StatelessWidget { //padding: EdgeInsets.fromLTRB(5, 5, 5, 5), ); } -} \ No newline at end of file +} diff --git a/example/pubspec.lock b/example/pubspec.lock index 69254f3..92c6d00 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -8,6 +8,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "0.36.4" + archive: + dependency: transitive + description: + name: archive + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.0.11" args: dependency: transitive description: @@ -21,7 +28,7 @@ packages: name: async url: "https://pub.flutter-io.cn" source: hosted - version: "2.3.0" + version: "2.4.0" boolean_selector: dependency: transitive description: @@ -50,13 +57,20 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.1.1" + coverage: + dependency: transitive + description: + name: coverage + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.13.3+3" crypto: dependency: transitive description: name: crypto url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.6" + version: "2.1.3" csslib: dependency: transitive description: @@ -123,6 +137,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "3.1.3" + image: + dependency: transitive + description: + name: image + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.1.4" io: dependency: transitive description: @@ -136,7 +157,7 @@ packages: path: ".." relative: true source: path - version: "0.3.0" + version: "0.5.0" js: dependency: transitive description: @@ -144,34 +165,34 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "0.6.1+1" - json_rpc_2: + kernel: dependency: transitive description: - name: json_rpc_2 + name: kernel url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.0" - kernel: + version: "0.3.19" + logging: dependency: transitive description: - name: kernel + name: logging url: "https://pub.flutter-io.cn" source: hosted - version: "0.3.19" + version: "0.11.3+2" matcher: dependency: transitive description: name: matcher url: "https://pub.flutter-io.cn" source: hosted - version: "0.12.5" + version: "0.12.6" meta: dependency: transitive description: name: meta url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.7" + version: "1.1.8" mime: dependency: transitive description: @@ -228,6 +249,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.8.0+1" + petitparser: + dependency: transitive + description: + name: petitparser + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.4.0" platform: dependency: transitive description: @@ -344,21 +372,21 @@ packages: name: test url: "https://pub.flutter-io.cn" source: hosted - version: "1.6.3" + version: "1.9.4" test_api: dependency: transitive description: name: test_api url: "https://pub.flutter-io.cn" source: hosted - version: "0.2.5" + version: "0.2.11" test_core: dependency: transitive description: name: test_core url: "https://pub.flutter-io.cn" source: hosted - version: "0.2.5" + version: "0.2.15" typed_data: dependency: transitive description: @@ -373,13 +401,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.0.8" - vm_service_client: + vm_service: dependency: transitive description: - name: vm_service_client + name: vm_service url: "https://pub.flutter-io.cn" source: hosted - version: "0.2.6+2" + version: "2.2.0" watcher: dependency: transitive description: @@ -394,6 +422,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.0.14" + xml: + dependency: transitive + description: + name: xml + url: "https://pub.flutter-io.cn" + source: hosted + version: "3.5.0" yaml: dependency: transitive description: @@ -402,4 +437,4 @@ packages: source: hosted version: "2.1.16" sdks: - dart: ">=2.2.2 <3.0.0" + dart: ">=2.6.0 <3.0.0" diff --git a/ios/Classes/JPushPlugin.m b/ios/Classes/JPushPlugin.m index 8352866..c55bedd 100644 --- a/ios/Classes/JPushPlugin.m +++ b/ios/Classes/JPushPlugin.m @@ -152,6 +152,10 @@ static NSMutableArray* getRidResults; [self getRegistrationID:call result:result]; } else if([@"sendLocalNotification"isEqualToString:call.method]) { [self sendLocalNotification:call result:result]; + } else if([@"isNotificationEnabled"isEqualToString:call.method]) { + [self isNotificationEnabled:call result:result]; + } else if([@"openSettingsForNotification"isEqualToString:call.method]) { + [self openSettingsForNotification]; } else{ result(FlutterMethodNotImplemented); } @@ -159,6 +163,7 @@ static NSMutableArray* getRidResults; + - (void)setup:(FlutterMethodCall*)call result:(FlutterResult)result { JPLog(@"setup:"); NSDictionary *arguments = call.arguments; @@ -436,6 +441,30 @@ static NSMutableArray* getRidResults; result(@[@[]]); } +/// 检查当前应用的通知开关是否开启 +- (void)isNotificationEnabled:(FlutterMethodCall*)call result:(FlutterResult)result { + JPLog(@"isNotificationEnabled:"); + [JPUSHService requestNotificationAuthorization:^(JPAuthorizationStatus status) { + BOOL isEnabled = NO; + if (status == JPAuthorizationStatusAuthorized) { + isEnabled = YES; + } + + NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:isEnabled],@"isEnabled", nil]; + dispatch_async(dispatch_get_main_queue(), ^{ + result(dict); + }); + }]; + + +} +- (void)openSettingsForNotification { + JPLog(@"openSettingsForNotification:"); + [JPUSHService openSettingsForNotification:^(BOOL success) { + JPLog(@"openSettingsForNotification: %@",@(success)); + }]; +} + - (void)dealloc { @@ -525,6 +554,19 @@ didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSe completionHandler(); } +- (void)jpushNotificationAuthorization:(JPAuthorizationStatus)status withInfo:(NSDictionary *)info { + BOOL isEnabled = NO; + if (status == JPAuthorizationStatusAuthorized) { + isEnabled = YES; + } + + NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:isEnabled],@"isEnabled", nil]; + __weak typeof(self) weakself = self; + dispatch_async(dispatch_get_main_queue(), ^{ + __strong typeof(self) strongself = weakself; + [strongself.channel invokeMethod:@"onReceiveNotificationAuthorization" arguments: dict]; + }); +} - (NSMutableDictionary *)jpushFormatAPNSDic:(NSDictionary *)dic { NSMutableDictionary *extras = @{}.mutableCopy; for (NSString *key in dic) { diff --git a/ios/jpush_flutter.podspec b/ios/jpush_flutter.podspec index f8265ab..a7c3f11 100644 --- a/ios/jpush_flutter.podspec +++ b/ios/jpush_flutter.podspec @@ -19,4 +19,4 @@ A new flutter plugin project. s.ios.deployment_target = '8.0' s.static_framework = true -end \ No newline at end of file +end diff --git a/lib/jpush_flutter.dart b/lib/jpush_flutter.dart index b5fa973..8f343a7 100644 --- a/lib/jpush_flutter.dart +++ b/lib/jpush_flutter.dart @@ -23,6 +23,7 @@ class JPush { EventHandler _onReceiveNotification; EventHandler _onOpenNotification; EventHandler _onReceiveMessage; + EventHandler _onReceiveNotificationAuthorization; void setup({ String appKey, @@ -47,12 +48,14 @@ class JPush { EventHandler onReceiveNotification, EventHandler onOpenNotification, EventHandler onReceiveMessage, + EventHandler onReceiveNotificationAuthorization, }) { print(flutter_log + "addEventHandler:"); _onReceiveNotification = onReceiveNotification; _onOpenNotification = onOpenNotification; _onReceiveMessage = onReceiveMessage; + _onReceiveNotificationAuthorization = onReceiveNotificationAuthorization; _channel.setMethodCallHandler(_handleMethod); } @@ -66,12 +69,15 @@ class JPush { return _onOpenNotification(call.arguments.cast()); case "onReceiveMessage": return _onReceiveMessage(call.arguments.cast()); + case "onReceiveNotificationAuthorization": + return _onReceiveNotificationAuthorization(call.arguments.cast()); default: throw new UnsupportedError("Unrecognized Event"); } } /// + /// iOS Only /// 申请推送权限,注意这个方法只会向用户弹出一次推送权限请求(如果用户不同意,之后只能用户到设置页面里面勾选相应权限),需要开发者选择合适的时机调用。 /// void applyPushAuthority( @@ -278,6 +284,17 @@ class JPush { } + /// 调用此 API 检测通知授权状态是否打开 + Future isNotificationEnabled() async { + final Map result = await _channel.invokeMethod('isNotificationEnabled'); + bool isEnabled = result["isEnabled"]; + return isEnabled; + } + + /// 调用此 API 跳转至系统设置中应用设置界面 + void openSettingsForNotification() { + _channel.invokeMethod('openSettingsForNotification'); + } } diff --git a/pubspec.lock b/pubspec.lock index 330b265..7468c9f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -145,7 +145,7 @@ packages: name: meta url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.7" + version: "1.1.8" mime: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 2f3c232..cb6fe92 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: jpush_flutter -description: Offically supported JPush Flutter plugin. -version: 0.3.0 +description: JIGUANG officially supported JPush Flutter plugin (Android & iOS). 极光推送官方支持的 Flutter 插件(Android & iOS)(https://www.jiguang.cn)。 +version: 0.5.0 author: xudong.rao homepage: https://www.jiguang.cn