File tree Expand file tree Collapse file tree 1 file changed +10
-10
lines changed
Expand file tree Collapse file tree 1 file changed +10
-10
lines changed Original file line number Diff line number Diff line change @@ -139,6 +139,16 @@ Java层方法可以返回void 或 能转为字符串的类型(如int、long、
139139 ...
140140 }
141141
142+ ### 小心过大数字
143+ JS中使用过大数字时,可能会导致精度丢失或者错误的数字结果,如下面:
144+
145+ HostApp.passLongType(14102300951321235)
146+ 传入一个大数** 14102300951321235** 到Java层,但Java层接收的数字实际上将会是** 14102300951321236** 这样一个错误的数字,所以当需要使用大数的情景下时,Java方法参数类型最好定义为** String类型** ,而js层调用时也转为string,比如上面就为
147+
148+ HostApp.passLongType(14102300951321235+'')。
149+
150+ 更多实现细节见: http://www.pedant.cn/2014/07/04/webview-js-java-interface-research/
151+
142152### 发布时防混淆
143153发布时需在你的混淆配置加入像下面这样的代码,注意返回到页面的自定义Java类以及注入到页面的接口类都要** 换成你项目中实际使用类名** :
144154
@@ -157,16 +167,6 @@ Java层方法可以返回void 或 能转为字符串的类型(如int、long、
157167 -keepclassmembers class cn.pedant.SafeWebViewBridge.sample.HostJsScope{ *; }
158168 #--------------- END ----------
159169
160- ### 小心过大数字
161- JS中使用过大数字时,可能会导致精度丢失或者错误的数字结果,如下面:
162-
163- HostApp.passLongType(14102300951321235)
164- 传入一个大数** 14102300951321235** 到Java层,但Java层接收的数字实际上将会是** 14102300951321236** 这样一个错误的数字,所以当需要使用大数的情景下时,Java方法参数类型最好定义为** String类型** ,而js层调用时也转为string,比如上面就为
165-
166- HostApp.passLongType(14102300951321235+'')。
167-
168- 更多实现细节见: http://www.pedant.cn/2014/07/04/webview-js-java-interface-research/
169-
170170## License
171171
172172 The MIT License (MIT)
You can’t perform that action at this time.
0 commit comments