我为Ipad制作了一个应用程序,它在simultor上工作正常但是当它安装在设备上进行测试时,数据库没有加载该值。
我正在为ios 4.3目标开发,我将sqlite数据库文件添加到支持文件夹中,并在Appdelegate文件中添加此代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self createDatabaseExecutableFile];
}
,方法代码是
// Creates a writable copy of the bundled default database in the application Documents directory.
- (void) createDatabaseExecutableFile
{
// First, test for existence.
BOOL _success;
NSFileManager* _fileManager = [NSFileManager defaultManager];
NSError* _error;
NSArray* _paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* _documentsDirectory = [_paths objectAtIndex:0];
NSString* _writableDBPath = [_documentsDirectory stringByAppendingPathComponent:@"turfnutritiontool_ver_two.db"];
_success = [_fileManager fileExistsAtPath:_writableDBPath];
if (_success)
return;
// The writable database does not exist, so copy the default to the appropriate location.
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"turfnutritiontool_ver_two.db"];
_success = [_fileManager copyItemAtPath:defaultDBPath toPath:_writableDBPath error:&_error];
if (!_success) {
NSAssert1(0, @"Failed to create writable database file with message '%@'.", [_error localizedDescription]);
}
}
答案 0 :(得分:0)
好吧,让我问你监狱打破你的ios设备......
任何方式逐行调试并检查是否
您的_writableDBPath值并检查db是否在该位置。
希望这会对你有所帮助