myths-Mac:~ myth$ pwd
/Users/myth
myths-Mac:~ myth$ react-native init sqliteApp
To run your app on iOS:
cd /Users/myth/sqliteApp
react-native run-ios
- or -
Open ios/sqliteApp.xcodeproj in Xcode
Hit the Run button
To run your app on Android:
cd /Users/myth/sqliteApp
Have an Android emulator running (quickest way to get started),or a device connected
react-native run-android
How to use (iOS):
myths-Mac:~ myth$ cd /Users/myth/sqliteApp && Open ios/sqliteApp.xcodeproj# Xcode 8 + 9
myths-Mac:~ myth$ sudo gem install cocoapods
myths-Mac:~ myth$ cd /Users/myth/sqliteApp && yarn add react-native-sqlite-storage
myths-Mac:~ myth$ cd /Users/myth/sqliteApp && ls
App.js android gen ios package.json
__tests__ app.json index.js node_modules yarn.lock
myths-Mac:~ myth$ cd /Users/myth/sqliteApp/ios && ls
sqliteApp sqliteApp-tvOSTests sqliteAppTests
sqliteApp-tvOS sqliteApp.xcodeproj
myths-Mac:~ myth$ cd /Users/myth/sqliteApp/ios && pod init && ls
Podfile sqliteApp-tvOS sqliteApp.xcodeproj
sqliteApp sqliteApp-tvOSTests sqliteAppTests
myths-Mac:~ myth$ cat /Users/myth/sqliteApp/ios/Podfile
# Uncomment the next line to define a global platform for your project
# platform :ios,'9.0'
target 'sqliteApp' do
# Uncomment the next line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!
# Pods for sqliteApp
target 'sqliteApp-tvOSTests' do
inherit! :search_paths
# Pods for testing
end
target 'sqliteAppTests' do
inherit! :search_paths
# Pods for testing
end
end
target 'sqliteApp-tvOS' do
# Uncomment the next line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!
# Pods for sqliteApp-tvOS
target 'sqliteApp-tvOSTests' do
inherit! :search_paths
# Pods for testing
end
end
myths-Mac:~ myth$
# Uncomment the next line to define a global platform for your project
platform :ios,'9.0'
target 'sqliteApp' do
# Uncomment the next line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!
# Pods for sqliteApp
pod 'yoga',:path => '../node_modules/react-native/ReactCommon/yoga'
pod 'React',:path => '../node_modules/react-native'
pod 'react-native-sqlite-storage',:path => '../node_modules/react-native-sqlite-storage'
end
上面的命令如何退出呢?先按回车键换行,然后按键盘组合键 Ctrl + D 结束Podfile文件内容写入,我非常喜欢这样去新建或者编辑文件的内容 整个背景色标识的一大块内容只是一条指令哦 在这方面,苹果终端命令与Linux终端命令的玩法一模一样
myths-Mac:~ myth$ cd /Users/myth/sqliteApp/ios && pod install
myths-Mac:~ myth$ cd /Users/myth/sqliteApp && rnpm link
rnpm-link info Linking react-native-sqlite-storage ios dependency
rnpm-link info iOS module react-native-sqlite-storage has been successfully linked
接下来讲如何创建 www 目录并且在终端中如何使用命令创建sqlite数据表
myths-Mac:~ myth$ cd /Users/myth/sqliteApp/ios/sqliteApp/www && sqlite3 petshop.db
sqlite version 3.16.0 2016-11-04 19:09:39
Enter ".help" for usage hints.
sqlite> create table pet(owner text primary key,petname text not null);
sqlite> insert into pet(owner,petname) values('Tom','Dog');
sqlite> sqlite> select * from pet;
Tom | Dog
Jason | Cat
sqlite> .exit
FoundXcodeworkspacesqliteApp.xcworkspace
CoreData:annotation:Failedtoloadoptimizedmodelatpath'/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/Frameworks/InstrumentsPackaging.framework/Versions/A/Resources/XRPackageModel.momd/XRPackageModel9.0.omo'
LaunchingiPhone6(iOS11.2)...
现在即使不写任何新代码,使用新建项目中默认的App.js文件代码 执行react-native run-ios会报告上面的错误
待续 ... ...