将数据复制到iPhone上的Application Data文件夹 [英] Copying data to the Application Data folder on the iPhone

查看:163
本文介绍了将数据复制到iPhone上的Application Data文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在(最后)将我的应用程序加载到iPhone设备上进行测试。到目前为止,我只在模拟器中测试了App。该应用程序是以数据为中心的,并使用SQLite数据库。我创建了一个适当的SQLite数据库,其中包含我在模拟器中使用的样本数据。如何将这个.sqlite3文件复制到实际的iPhone?

I am in the process of (finally) loading my App onto an iPhone device for testing. So far I have only tested the App in the simulator. The application is data-centric and uses an SQLite database. I have created an appropriate SQLite database with sample data which I used in the simulator. How can I copy this .sqlite3 file to the actual iPhone?

使用模拟器这很容易,因为我可以将.sqlite3文件复制到〜/库/应用程序支持/ iPhone模拟器/用户/应用程序/ {UUID} /文档文件夹,但我无法弄清楚如何将它放到实际iPhone设备上的相同位置。在手机上重新创建数据库并不是一个真正的选择,因为我已经完成了在Mac上创建数据库的所有硬码。

This was easy with the simulator as I could just copy the .sqlite3 file into the ~/Library/Application Support/iPhone Simulator/User/Applications/{UUID}/Documents folder, but I cannot figure out how to get this into the same location on the actual iPhone device. Recreating the database from scratch on the phone is not really an option, as I have already done all the hard-yards creating the database on the Mac.

推荐答案

为什么不将它添加到您的应用程序包中?右键单击Xco​​de中项目窗口中的 Resources 文件夹,然后选择添加> 现有文件... 添加你的sqlite数据库。

Why not add it to your application bundle? Right-click on the Resources folder in your project window in Xcode, then select Add > Existing Files... to add your sqlite database.

然后你将从应用程序包中加载文件:

You would then load the file from the application bundle:

NSString *databasePath = [[NSBundle mainBundle] pathForResource:@"mySQLiteDatabaseFile" ofType:@"sqlite3"];
NSData *databaseData = [NSData dataWithContentsOfFile:databasePath];
// ...

这篇关于将数据复制到iPhone上的Application Data文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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