Skip to content

Commit 796e381

Browse files
authored
Merge pull request #36 from jpush/dev
v0.6.1
2 parents 00e7caa + bb6a981 commit 796e381

File tree

17 files changed

+427
-231
lines changed

17 files changed

+427
-231
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 0.6.1
2+
+ 优化:Android 回调 flutter 的回调函数
3+
+ 优化重复请求逻辑
14
## 0.6.0
25
+ 新增:SDK 初始化回调监听
36
+ 新增:授权页弹窗模式

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,23 @@
55

66
在工程 pubspec.yaml 中加入 dependencies
77

8-
```yaml
9-
//pub 集成
10-
dependencies:
11-
jverify: 0.6.0
8+
+ github 集成
129

13-
14-
//github 集成
10+
```
1511
dependencies:
1612
jverify:
1713
git:
1814
url: git://github.com/jpush/jverify-flutter-plugin.git
1915
ref: master
2016
```
17+
18+
+ pub 集成
19+
20+
```
21+
dependencies:
22+
jverify: 0.6.1
23+
```
24+
2125
### 配置
2226

2327
##### Android:

android/src/main/java/com/jiguang/jverify/JverifyPlugin.java

Lines changed: 83 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
import android.graphics.drawable.StateListDrawable;
1111
import android.media.Image;
1212
import android.nfc.Tag;
13+
import android.os.Handler;
14+
import android.os.HandlerThread;
15+
import android.os.Looper;
1316
import android.util.Log;
1417
import android.util.TypedValue;
1518
import android.view.Gravity;
@@ -43,6 +46,11 @@
4346
import io.flutter.plugin.common.MethodChannel.Result;
4447
import io.flutter.plugin.common.PluginRegistry.Registrar;
4548

49+
class JVRequestItem {
50+
public MethodCall call;
51+
Result result;
52+
}
53+
4654
/** JverifyPlugin */
4755
public class JverifyPlugin implements MethodCallHandler {
4856

@@ -60,10 +68,13 @@ public class JverifyPlugin implements MethodCallHandler {
6068
private static String j_opr_key = "operator";
6169
// 默认超时时间
6270
private static int j_default_timeout = 5000;
71+
// 重复请求
72+
private static int j_error_code_repeat = -1;
6373

6474

6575
private Context context;
6676
private MethodChannel channel;
77+
private HashMap<String,JVRequestItem> requestQueue = new HashMap();
6778

6879
/** Plugin registration. */
6980
public static void registerWith(Registrar registrar) {
@@ -81,6 +92,29 @@ private JverifyPlugin(Registrar registrar,MethodChannel channel){
8192
public void onMethodCall(MethodCall call, Result result) {
8293
Log.d(TAG,"onMethodCall:" + call.method);
8394

95+
// JVRequestItem item = requestQueue.get(call.method);
96+
// if (item == null) {
97+
// item = new JVRequestItem();
98+
// item.call = call;
99+
// item.result = result;
100+
//
101+
// requestQueue.put(call.method,item);
102+
//
103+
// processMethod(call, result);
104+
// }else {
105+
// String error_repeat_desc = call.method + " is requesting, please try again later.";
106+
//
107+
// Map<String,Object> map = new HashMap<>();
108+
// map.put(j_code_key,j_error_code_repeat);
109+
// map.put(j_msg_key,error_repeat_desc);
110+
//
111+
// result.success(map);
112+
// }
113+
processMethod(call,result);
114+
}
115+
116+
private void processMethod(MethodCall call, Result result) {
117+
Log.d(TAG,"processMethod:" + call.method);
84118
if (call.method.equals("setup")) {
85119
setup(call,result);
86120
}else if (call.method.equals("setDebugMode")) {
@@ -115,6 +149,34 @@ public void onMethodCall(MethodCall call, Result result) {
115149
}
116150
}
117151

152+
private void methodCallBack(Object object,String method) {
153+
Log.d(TAG,"Action - methodCallBack:" + method);
154+
155+
JVRequestItem item = requestQueue.get(method);
156+
if (item != null) {
157+
if (item.result != null) {
158+
item.result.success(object);
159+
}
160+
}
161+
requestQueue.remove(method);
162+
}
163+
164+
// 主线程再返回数据
165+
private void runMainThread(final Map<String,Object> map, final Result result, final String method) {
166+
android.os.Handler handler = new Handler(Looper.getMainLooper());
167+
handler.post(new Runnable() {
168+
@Override
169+
public void run() {
170+
if (result == null && method != null){
171+
channel.invokeMethod(method,map);
172+
} else {
173+
result.success(map);
174+
}
175+
}
176+
});
177+
}
178+
179+
118180
/** SDK 初始换 */
119181
private void setup(MethodCall call,Result result){
120182
Log.d(TAG,"Action - setup:");
@@ -127,7 +189,8 @@ public void onResult(int code, String message) {
127189
map.put(j_code_key,code);
128190
map.put(j_msg_key,message);
129191
// 通过 channel 返回
130-
channel.invokeMethod("onReceiveSDKSetupCallBackEvent",map);
192+
//channel.invokeMethod("onReceiveSDKSetupCallBackEvent",map);
193+
runMainThread(map,null,"onReceiveSDKSetupCallBackEvent");
131194
}
132195
});
133196
}
@@ -142,7 +205,7 @@ private void setDebugMode(MethodCall call,Result result){
142205

143206
Map<String,Object> map = new HashMap<>();
144207
map.put(j_result_key,enable);
145-
result.success(map);
208+
runMainThread(map,result,null);
146209
}
147210

148211
/** 获取 SDK 初始化是否成功标识 */
@@ -155,7 +218,7 @@ private boolean isInitSuccess(MethodCall call, Result result) {
155218

156219
Map<String,Object> map = new HashMap<>();
157220
map.put(j_result_key, isSuccess);
158-
result.success(map);
221+
runMainThread(map,result,null);
159222

160223
return isSuccess;
161224
}
@@ -171,13 +234,13 @@ private boolean checkVerifyEnable(MethodCall call,Result result){
171234

172235
Map<String,Object> map = new HashMap<>();
173236
map.put(j_result_key, verifyEnable);
174-
result.success(map);
237+
runMainThread(map,result,null);
175238

176239
return verifyEnable;
177240
}
178241

179242
/** SDK获取号码认证token*/
180-
private void getToken(MethodCall call, final Result result) {
243+
private void getToken(final MethodCall call, final Result result) {
181244
Log.d(TAG,"Action - getToken:");
182245

183246
int timeOut = j_default_timeout;
@@ -206,7 +269,8 @@ public void onResult(int code, String content, String operator) {
206269
map.put(j_code_key,code);
207270
map.put(j_msg_key,content);
208271
map.put(j_opr_key,operator);
209-
result.success(map);
272+
273+
runMainThread(map,result,null);
210274
}
211275
});
212276
}
@@ -251,7 +315,7 @@ public void onResult(int code, String content, String operator) {
251315
}
252316

253317
/** SDK 一键登录预取号 */
254-
private void preLogin(MethodCall call,final Result result) {
318+
private void preLogin(final MethodCall call, final Result result) {
255319
Log.d(TAG,"Action - preLogin:" + call.arguments);
256320

257321
int timeOut = j_default_timeout;
@@ -265,19 +329,21 @@ private void preLogin(MethodCall call,final Result result) {
265329
public void onResult(int code, String message) {
266330

267331
if (code == 7000){//code: 返回码,7000代表获取成功,其他为失败,详见错误码描述
268-
Log.d(TAG, "verify consistent, message =" + message);
332+
Log.d(TAG, "verify success, message =" + message);
269333
}else {
270-
Log.e(TAG, "code=" + code + ", message =" + message);
334+
Log.e(TAG, "verify fail,code=" + code + ", message =" + message);
271335
}
272-
273336
Map<String,Object> map = new HashMap<>();
274337
map.put(j_code_key,code);
275338
map.put(j_msg_key,message);
276-
result.success(map);
339+
340+
runMainThread(map,result,null);
277341
}
278342
});
279343
}
280344

345+
346+
281347
/** SDK清除预取号缓存 */
282348
private void clearPreLoginCache(MethodCall call,final Result result) {
283349
Log.d(TAG,"Action - clearPreLoginCache:");
@@ -295,7 +361,7 @@ private void loginAuthSyncApi(MethodCall call,final Result result) {
295361
Log.d(TAG,"Action - loginAuthSyncApi:");
296362
loginAuthInterface(true,call,result);
297363
}
298-
private void loginAuthInterface(final Boolean isSync, MethodCall call, final Result result) {
364+
private void loginAuthInterface(final Boolean isSync, final MethodCall call, final Result result) {
299365
Log.d(TAG,"Action - loginAuthInterface:");
300366

301367
Object autoFinish = getValueByKey(call,"autoDismiss");
@@ -312,7 +378,8 @@ public void onEvent(int cmd, String msg) {
312378
final HashMap jsonMap = new HashMap();
313379
jsonMap.put(j_code_key, cmd);
314380
jsonMap.put(j_msg_key, msg);
315-
channel.invokeMethod("onReceiveAuthPageEvent", jsonMap);
381+
382+
runMainThread(jsonMap,null,"onReceiveAuthPageEvent");
316383
}
317384
});
318385

@@ -330,10 +397,10 @@ public void onResult(int code, String content, String operator) {
330397
map.put(j_opr_key,operator);
331398
if (isSync) {
332399
// 通过 channel 返回
333-
channel.invokeMethod("onReceiveLoginAuthCallBackEvent",map);
400+
runMainThread(map,null,"onReceiveLoginAuthCallBackEvent");
334401
}else {
335402
// 通过回调返回
336-
result.success(map);
403+
runMainThread(map,result,null);
337404
}
338405
}
339406
});
@@ -928,7 +995,7 @@ private void addCustomButtonWidgets(Map para, JVerifyUIConfig.Builder builder)
928995
@Override
929996
public void onClicked(Context context, View view) {
930997
Log.d(TAG,"onClicked button widget.");
931-
channel.invokeMethod("onReceiveClickWidgetEvent", jsonMap);
998+
runMainThread(jsonMap,null,"onReceiveClickWidgetEvent");
932999
}
9331000
});
9341001
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"_info":"// This is a generated file; do not edit or check into version control.","dependencyGraph":[{"name":"jverify","dependencies":[]}]}

example/android/app/build.gradle

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ apply plugin: 'com.android.application'
2525
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
2626

2727
android {
28-
compileSdkVersion 27
28+
compileSdkVersion 28
2929

3030
lintOptions {
3131
disable 'InvalidPackage'
@@ -35,7 +35,7 @@ android {
3535
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
3636
applicationId "cn.jiguang.xx" // 应用包名
3737
minSdkVersion 16
38-
targetSdkVersion 27
38+
targetSdkVersion 28
3939
versionCode flutterVersionCode.toInteger()
4040
versionName flutterVersionName
4141
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@@ -53,10 +53,23 @@ android {
5353
]
5454
}
5555

56+
signingConfigs {
57+
release {
58+
keyAlias 'androiddebugkey'
59+
keyPassword 'android'
60+
storePassword 'android'
61+
storeFile file('debug.keystore')
62+
}
63+
debug {
64+
storeFile file('debug.keystore')
65+
}
66+
}
5667
buildTypes {
5768
release {
58-
// TODO: Add your own signing config for the release build.
59-
// Signing with the debug keys for now, so `flutter run --release` works.
69+
signingConfig signingConfigs.release
70+
shrinkResources false
71+
}
72+
debug {
6073
signingConfig signingConfigs.debug
6174
}
6275
}

example/android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
additional functionality it is fine to subclass or reimplement
88
FlutterApplication and put your custom class here. -->
99
<application
10+
android:networkSecurityConfig="@xml/network_security_config"
1011
android:name="io.flutter.app.FlutterApplication"
1112
android:label="jverify_example"
1213
android:icon="@mipmap/ic_launcher">
File renamed without changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<network-security-config>
3+
<base-config cleartextTrafficPermitted="true">
4+
<trust-anchors>
5+
<certificates src="system" />
6+
</trust-anchors>
7+
</base-config>
8+
</network-security-config>

example/android/gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
org.gradle.jvmargs=-Xmx1536M
2+
android.enableR8=true

example/ios/Flutter/flutter_export_environment.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
# This is a generated file; do not edit or check into version control.
33
export "FLUTTER_ROOT=/Applications/flutter"
44
export "FLUTTER_APPLICATION_PATH=/Users/raoxudong/JPush/jpush-github/jverify-flutter-plugin/example"
5-
export "FLUTTER_TARGET=/Users/raoxudong/JPush/jpush-github/jverify-flutter-plugin/example/lib/main.dart"
5+
export "FLUTTER_TARGET=lib/main.dart"
66
export "FLUTTER_BUILD_DIR=build"
77
export "SYMROOT=${SOURCE_ROOT}/../build/ios"
88
export "FLUTTER_FRAMEWORK_DIR=/Applications/flutter/bin/cache/artifacts/engine/ios"
9-
export "TRACK_WIDGET_CREATION=true"
9+
export "FLUTTER_BUILD_NAME=1.0.0"
10+
export "FLUTTER_BUILD_NUMBER=1"

0 commit comments

Comments
 (0)