简体   繁体   English

在本机应用程序和html5之间共享sqlite数据库

[英]Share sqlite database between native app and html5

I have a small native app for iPad with UIWebView only. 我有一个用于iPad的小型本机应用程序,仅具有UIWebView。 This app can store data in SQLite database. 该应用程序可以将数据存储在SQLite数据库中。 Can I read this database in JS from web page inside the UIWebView? 我可以从UIWebView内的网页中以JS读取此数据库吗? Where does the browser store database files for SQLite? 浏览器在哪里存储SQLite的数据库文件? Could the database be shared between web page and native app? 可以在网页和本机应用程序之间共享数据库吗?

Thanks a lot. 非常感谢。

You can not use the db or any other resource inside the ios app outside of it. 您不能在数据库之外的ios应用程序内部使用数据库或任何其他资源。

Because ios apps run in sandboxed environment. 因为ios应用程序在沙盒环境中运行。 Each and every app is allocated some folder space it can put and get from that only for example documents directory, library directory 每个应用程序都分配有一些文件夹空间,该文件夹空间只能从其中获取,例如文档目录,库目录

if you know some common scripting languages like php or classic asp you can do that easily. 如果您知道一些常用的脚本语言,例如php或classic asp,则可以轻松实现。

for example 例如

build a string with html tags, css and script 用html标签,css和脚本构建一个字符串

then load that string in webview 然后在webview中加载该字符串

you can hide some data in hidden field and use it whenever you need it. 您可以在隐藏字段中隐藏一些数据,并在需要时使用它们。 If it needs to access some big sqlite data at the time just make a url request catch the url request in objective c and again build and load the string. 如果它当时需要访问一些大型sqlite数据,则只需使一个url请求在目标c中捕获该url请求,然后再次构建并加载该字符串即可。

you can make requests to app from webview and get callback, us JS and UIWebViewDelegate or any other 您可以从webview向应用发出请求并获取回调,例如JS和UIWebViewDelegate或任何其他

HTML: HTML:

<a href=\"http://commenter\">

in application: 在应用中:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    NSString *button = [[request URL] host];

    // if clicked on commenter/partager button in article
    if ([button isEqualToString:@"commenter"]) {

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM