Skip to content

Commit d7fc806

Browse files
clozrandpor
clozr
authored andcommitted
Master (andpor#47)
rnpm link support for iOS
1 parent 8fbb877 commit d7fc806

File tree

5 files changed

+59
-14
lines changed

5 files changed

+59
-14
lines changed

README.md

+10-14
Original file line numberDiff line numberDiff line change
@@ -51,27 +51,23 @@ v1.0 - Intial release for iOS with full support of all operations based on plan
5151

5252
```shell
5353
npm install --save react-native-sqlite-storage
54+
rnpm link
5455
```
56+
If rnpm is not already installed you can install it as follows:
57+
```shell
58+
npm -g install rnpm xcode
59+
```
60+
After linking project should like this:
5561

56-
#### Step 2. XCode SQLite project dependency set up
57-
58-
Drag the SQLite Xcode project as a dependency project into your React Native XCode project
59-
60-
![alt tag](https://raw.github.com/andpor/react-native-sqlite-storage/master/instructions/libs.png)
61-
62-
#### Step 3. XCode SQLite libraries dependency set up
63-
64-
Add libSQLite.a (from Workspace location) to the required Libraries and Frameworks. Also add sqlite3.0.tbd (XCode 7) or libsqlite3.0.dylib (XCode 6 and earlier) in the same fashion using Required Libraries view (Do not just add them manually as the build paths will not be properly set)
65-
66-
![alt tag](https://raw.github.com/andpor/react-native-sqlite-storage/master/instructions/addlibs.png)
62+
![alt tag](instructions/after-rnpm.png)
6763

68-
#### Step 4. Application JavaScript require
64+
#### Step 2. Application JavaScript require
6965

7066
Add var SQLite = require('react-native-sqlite-storage') to your index.ios.js
7167

72-
![alt tag](https://raw.github.com/andpor/react-native-sqlite-storage/master/instructions/require.png)
68+
![alt tag](instructions/require.png)
7369

74-
#### Step 5. Applicatin JavaScript code using the SQLite plugin
70+
#### Step 3. Applicatin JavaScript code using the SQLite plugin
7571

7672
Add JS application code to use SQLite API in your index.ios.js etc. Here is some sample code. For full working example see test/index.ios.callback.js. Please note that Promise based API is now supported as well with full examples in the working React Native app under test/index.ios.promise.js
7773

instructions/after-rnpm.png

355 KB
Loading

instructions/before-rnpm.png

352 KB
Loading

package.json

+12
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,17 @@
3131
"homepage": "https://github.com/andpor/react-native-sqlite-storage",
3232
"peerDependencies": {
3333
"react-native": ">=0.14.0"
34+
},
35+
"dependencies": {
36+
"rnpm": "1.5.2",
37+
"xcode": "0.8.4"
38+
},
39+
"rnpm": {
40+
"commands": {
41+
"postlink": "node_modules/react-native-sqlite-storage/scripts/rnpm-postlink.js"
42+
},
43+
"ios": {
44+
"project": "src/ios/SQLite.xcodeproj"
45+
}
3446
}
3547
}

scripts/rnpm-postlink.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env node
2+
3+
'use strict';
4+
5+
var fs = require('fs');
6+
var rnpm = require('rnpm/src/config');
7+
var xcode = require('xcode');
8+
9+
// The current working directory should be project root of the app that is linking react-native-sqlite.
10+
var config = rnpm.getProjectConfig();
11+
12+
if (config.ios) {
13+
var pbxproj = config.ios.pbxprojPath;
14+
var project = xcode.project(pbxproj).parseSync();
15+
var target = project.getFirstTarget().uuid;
16+
17+
// Create a Frameworks group if necessary.
18+
if (!project.pbxGroupByName('Frameworks')) {
19+
var group = project.pbxCreateGroup('Frameworks', '""');
20+
var mainGroup = project.getFirstProject().firstProject.mainGroup;
21+
22+
project.getPBXGroupByKey(mainGroup).children.push({
23+
value: group,
24+
comment: 'Frameworks',
25+
});
26+
}
27+
28+
['libsqlite3.0'].forEach(function(name) {
29+
project.addFramework('usr/lib/' + name + '.tbd', {
30+
lastKnownFileType: 'sourcecode.text-based-dylib-definition',
31+
sourceTree: 'SDKROOT',
32+
target: target,
33+
});
34+
});
35+
36+
fs.writeFileSync(pbxproj, project.writeSync());
37+
}

0 commit comments

Comments
 (0)