Browse Source

Add rnpm script for change android permission

Ben Hsieh 8 years ago
parent
commit
54c5181182
2 changed files with 24 additions and 1 deletions
  1. 6
    1
      src/package.json
  2. 18
    0
      src/scripts/prelink.js

+ 6
- 1
src/package.json View File

@@ -1,6 +1,6 @@
1 1
 {
2 2
   "name": "react-native-fetch-blob",
3
-  "version": "0.4.2",
3
+  "version": "0.5.0",
4 4
   "description": "A react-native plugin for fetch blob data via HTTP.",
5 5
   "main": "index.js",
6 6
   "scripts": {
@@ -15,6 +15,11 @@
15 15
     "blob",
16 16
     "image header"
17 17
   ],
18
+  "rnpm": {
19
+		"commands": {
20
+			"prelink": "node ./node_modules/react-native-fetch-blob/scripts/prelink.js"
21
+		}
22
+	},
18 23
   "repository": {
19 24
     "url": "https://github.com/wkh237/react-native-fetch-blob.git"
20 25
   },

+ 18
- 0
src/scripts/prelink.js View File

@@ -0,0 +1,18 @@
1
+var fs = reuqire('fs');
2
+var MANIFEST_PATH = process.cwd() + '/android/app/src/main/AndroidManifest.xml';
3
+
4
+fs.readFile(MANIFEST_PATH, function(err, data) {
5
+
6
+  if(err)
7
+    console.log('failed to locate AndroidManifest.xml file, you may have to add file access permission manually.');
8
+  else {
9
+
10
+    data = String(data).replace(
11
+      '<uses-permission android:name="android.permission.INTERNET" />',
12
+      '<uses-permission android:name="android.permission.INTERNET" />\n  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> '
13
+    )
14
+    fs.writeFileSync(MANIFEST_PATH, data);
15
+
16
+  }
17
+
18
+})