带有预先填充的sqlite数据库的iOS发货申请表 [英] iOS ship application with pre populated sqlite database

查看:113
本文介绍了带有预先填充的sqlite数据库的iOS发货申请表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用我预先填充的sqlite数据库发送我的ios应用程序(用swift编写),该数据库将通过与服务器同步来更新。在android我可以将数据库从assests文件夹移动到数据库和volla,但在ios我很安静,我怎么能实现这个目标?

I want to ship my ios application(written in swift) with my pre populated sqlite database which will be updated through syncing with server. In android I could move the db from assests folder to databases and volla, but in ios I'm quiet lost how can I achieve this?

谢谢

推荐答案

在iOS中,您可以将数据库添加到项目支持文件中。这将添加二进制文件,然后您可以访问并复制它。

In iOS you can add the database into the Project Supporting files. This will be added in with the binary, which you can then access and copy it across.

NSBundle

let databasePath = NSBundle.mainBundle().URLForResource("databaseName", withExtension:"sqlite3");

使用 NSFileManager

//Should have an error pointed in case there is an error.
let documentsDirectory = NSFileManager.defaultManager().URLForDirectory(NSSearchPathDirectory.DocumentDirectory, inDomain:NSSearchPathDomainMask.UserDomainMask, url:nil, shouldCreate:false, error:nil);

最后复制文件:

if let source = databasePath, destination = documentsDirectory
{
   destination = destination.URLByAppendingPathComponent("database.sqlite3")
   var result = NSFileManager.defaultManager().copyItemAtURL(source, toURL:destination, error:nil)

   //Should have an error pointer, check that the result is true. If not check error.
}

这篇关于带有预先填充的sqlite数据库的iOS发货申请表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆