带有预先填充的sqlite数据库的iOS发货申请
发布时间:2020-12-12 19:12:58 所属栏目:百科 来源:网络整理
导读:我想用我预先填充的sqlite数据库发送我的ios应用程序(用swift编写),该数据库将通过与服务器同步来更新.在android我可以将数据库从assests文件夹移动到数据库和volla,但在ios我很安静,我怎么能实现这个? 谢谢 在iOS中,您可以将数据库添加到项目支持文件中.这
我想用我预先填充的sqlite数据库发送我的ios应用程序(用swift编写),该数据库将通过与服务器同步来更新.在android我可以将数据库从assests文件夹移动到数据库和volla,但在ios我很安静,我怎么能实现这个?
谢谢 在iOS中,您可以将数据库添加到项目支持文件中.这将添加二进制文件,然后您可以访问并复制它.要从NSBundle获取预先填充的数据库的位置: let databasePath = NSBundle.mainBundle().URLForResource("databaseName",withExtension:"sqlite3"); 使用NSFileManager获取文档目录的URL: //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. } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |