首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Iphone >

数据库联机有关问题

2012-01-28 
数据库联机问题我自己建立数据库,在mac上面用模拟器测试的时候可以直接将数据库拷贝到document文件夹下,通

数据库联机问题
我自己建立数据库,在mac上面用模拟器测试的时候可以直接将数据库拷贝到document文件夹下,通过-(NSString *)dataFilePath{

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

return [documentsDirectory stringByAppendingPathComponent:kFilename];

}方法找到,但是我联机到真机上面测试的时候就找不到了,我在iphone上面测试的时候应该把数据库放在项目文件夹的什么地方啊,因为是客户自己下载的,我希望能项目到iphone上面运行的时候就能连接数据库,因为数据库里面的数据有很多条,所以不能下载和自己创建,就自己放在项目文件夹下怎么能让程序正常使用,很急,希望各位多多照顾!!

[解决办法]
那就先放在包里然后拷贝过去

C/C++ code
NSString *localDBPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"XX.db"];    if (![[NSFileManager defaultManager] fileExistsAtPath:localDBPath]) {        NSString *bundleDBPath = [[NSBundle mainBundle] pathForResource:@"XX" ofType:@"db"];        [[NSFileManager defaultManager] copyItemAtPath:bundleDBPath toPath:localDBPath error:nil];    } 

热点排行