好的。現在將該數據庫複製到任何將作爲應用程序數據存儲的本地位置。下面給出的代碼也會這樣做。
NSArray *docPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *docDir = [docPaths objectAtIndex:0];
NSString *dbPath = [[docDir stringByAppendingPathComponent:@"person.rsd"] retain];
NSFileManager *fm = [NSFileManager defaultManager];
BOOL success = [fm fileExistsAtPath:dbPath];
if(success) return;
NSString *dbPathFromApp=[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent :@"person.rsd"];
[fm copyItemAtPath:dbPathFromApp toPath:dbPath error:nil];
之後,執行您的查詢,您將在應用程序模擬器文件夾中獲取插入的數據。
您是否已將源數據庫與應用程序相關聯? –
是啊..我重視.. –
不知道在IOS sqllite,但我想你忘了提交更改到數據庫 http://www.techotopia.com/index.php/An_Example_SQLite_based_iOS_4_iPhone_Application#Implementing_the_Code_to_Save_Data_to_the_SQLite_Database – Seega