我正在使用cordova 3.0 构建一个混合应用程序。我使用插件将我的数据存储在 sqlite 数据库中。在 android 和 ios 上,我有一些脚本,它们将数据库复制到应用程序的“文档”文件夹中,我可以在其中读取/写入该预填充的数据库。现在我想在 Windows Phone 8 上存档。
我找到了一个教程:
http://wp.qmatteoq.com/import-an-already-existing-sqlite-database-in-a-windows-8-application/
但这与 Cordova 无关。
这就是我的代码的样子:
namespace com.example.hello
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
this.CordovaView.Loaded += CordovaView_Loaded;
}
private async void CordovaView_Loaded(object sender, RoutedEventArgs e)
{
await CopyDatabase();
this.CordovaView.Loaded -= CordovaView_Loaded;
}
private async Task CopyDatabase()
{
bool isDatabaseExisting = false;
try
{
StorageFile storageFile = await ApplicationData.Current.LocalFolder.GetFileAsync("my.db");
isDatabaseExisting = true;
}
catch
{
isDatabaseExisting = false;
}
if (!isDatabaseExisting)
{
StorageFile databaseFile = await Package.Current.InstalledLocation.GetFileAsync("my.db");
await databaseFile.CopyAsync(ApplicationData.Current.LocalFolder);
}
}
}
}
但我总是得到一个异常“System.IO.FileNotFoundException”。但是 .db 文件仍然在正确的位置。如果我使用片段显示“ApplicationData.Current.LocalFolder”中的所有文件,我的 sqlite 填充仍然存在。
我也有一个截图的要点https://gist.github.com/pille72/9615840
最佳答案
从 Resource
更改构建操作至Content
.
关于c# - 如何在带有cordova的windows phone 8上使用现有的sqlite数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22483345/