加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

react-native How to use Sqlite in Android and iOS System

发布时间:2020-12-15 06:31:34 所属栏目:百科 来源:网络整理
导读: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 Androi

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$



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
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> select * from pet;
Tom | Dog
Jason | Cat
sqlite> .exit


myths-Mac:~ myth$ react-native run-ios
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会报告上面的错误

待续 ... ...

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读