解决方法
你可以添加以下方法给你的appdelegate
- (void) copyDatabaseIfNeeded { //Using NSFileManager we can perform many file sy@R_502_6063@ operations. NSFileManager *fileManager = [NSFileManager defaultManager]; NSError *error; Nsstring *dbPath = [self getDBPath]; BOOL success = [fileManager fileExistsAtPath:dbPath]; if(!success) { Nsstring *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"database.sqlite"]; success = [fileManager copyItemAtPath:defaultDBPath toPath:dbPath error:&error]; if (!success) NSAssert1(0,@"Failed to create writable database file with message '%@'.",[error localizedDescription]); } } - (Nsstring *) getDBPath { //Search for standard documents using NSSearchPathForDirectoriesInDomains //First Param = Searching the documents directory //Second Param = Searching the Users directory and not the Sy@R_502_6063@ //Expand any tildes and identify home directories. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); Nsstring *documentsDir = [paths objectAtIndex:0]; //NSLog(@"dbpath : %@",documentsDir); return [documentsDir stringByAppendingPathComponent:@"database.sqlite"]; }