在运行iOS 5.0.1的iPhone 4中,在Wi-Fi和蜂窝网络上都没有连接Sqlite3数据库。由于这个原因,我的应用程序4次在Itunes Apple商店被拒绝。 我正在使用iPhone 3.2 iOS 4.1的XCode 3.2.4。这个应用运行良好的地方。
我写下这些代码 -
/// @ AppDelegate.m file
-(void)createDatabaseIfNeeded {
BOOL success;
NSError *error;
//FileManager - Object allows easy access to the File System.
NSFileManager *FileManager = [NSFileManager defaultManager];
//Get the complete users document directory path.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//Get the first path in the array.
NSString *documentsDirectory = [paths objectAtIndex:0];
//Create the complete path to the database file.
NSString *databasePath = [documentsDirectory stringByAppendingPathComponent:@"passmanager.sqlite"];
//Check if the file exists or not.
success = [FileManager fileExistsAtPath:databasePath];
//If the database is present then quit.
if(success) return;
//the database does not exists, so we will copy it to the users document directory]
NSString *dbPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"passmanager.sqlite"];
//Copy the database file to the users document directory.
success = [FileManager copyItemAtPath:dbPath toPath:databasePath error:&error];
//If the above operation is not a success then display a message.
//Error message can be seen in the debugger's console window.
if(!success)
NSAssert1(0, @"Failed to copy the database. Error: %@.", [error localizedDescription]);
}
-(void)applicationDidFinishLaunching:(UIApplication *)application{
// createDatabaseIfNeeded method for first time to create database in new iPhone
[self createDatabaseIfNeeded];
[window addSubview:navigationController.view];
[window makeKeyAndVisible];
}
并且Error在某些ViewController页面的代码
中给Apple带来了压缩// @ viewController.m
sqlite3 *database;
int result = sqlite3_open("passmanager.sqlite", &database);
if(result != SQLITE_OK){
sqlite3_close(database);
UIAlertView *alert =
[[UIAlertView alloc] initWithTitle:@"Database Connected"
message:@"No"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
else{
// some stuff
}
每次Apple都抱怨如果条件为“数据库连接否” 在我的系统中,其他部分正在执行。 请帮我。 Thax先进。
答案 0 :(得分:3)
您尝试打开的数据库路径看起来不完整,应该是
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *databasePath = [documentsDirectory stringByAppendingPathComponent:@"passmanager.sqlite"];
int result = sqlite3_open([databasePath UTF8String], &database);
因为这是您在createDatabaseIfNeeded