瀏覽代碼

Merge pull request #149 from studiozeffa/fix/cp-illegal-callback-invocation

Fix 'Illegal Callback Invocation' Android exception
Travis Nuttall 6 年之前
父節點
當前提交
d07567396b
No account linked to committer's email address
共有 1 個文件被更改,包括 10 次插入3 次删除
  1. 10
    3
      android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java

+ 10
- 3
android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java 查看文件

@@ -548,6 +548,7 @@ class RNFetchBlobFS {
548 548
         path = normalizePath(path);
549 549
         InputStream in = null;
550 550
         OutputStream out = null;
551
+        String message = "";
551 552
 
552 553
         try {
553 554
             if(!isPathExists(path)) {
@@ -571,7 +572,7 @@ class RNFetchBlobFS {
571 572
                 out.write(buf, 0, len);
572 573
             }
573 574
         } catch (Exception err) {
574
-            callback.invoke(err.getLocalizedMessage());
575
+            message += err.getLocalizedMessage();
575 576
         } finally {
576 577
             try {
577 578
                 if (in != null) {
@@ -580,11 +581,17 @@ class RNFetchBlobFS {
580 581
                 if (out != null) {
581 582
                     out.close();
582 583
                 }
583
-                callback.invoke();
584 584
             } catch (Exception e) {
585
-                callback.invoke(e.getLocalizedMessage());
585
+                message += e.getLocalizedMessage();
586 586
             }
587 587
         }
588
+        // Only call the callback once to prevent the app from crashing
589
+        // with an 'Illegal callback invocation from native module' exception.
590
+        if (message != "") {
591
+            callback.invoke(message);
592
+        } else {
593
+            callback.invoke();
594
+        }
588 595
     }
589 596
 
590 597
     /**