0
Iamd開發了一個應用程序。在那裏我使用了sqlite數據。當iam在模擬器中運行時,數據保存在數據庫中。並且當我檢索數據時沒有問題。但是當iam在設備中運行時,檢索數據的時間。請告訴我我能做些什麼來解決這個問題。如何處理設備中的數據庫?
Iamd開發了一個應用程序。在那裏我使用了sqlite數據。當iam在模擬器中運行時,數據保存在數據庫中。並且當我檢索數據時沒有問題。但是當iam在設備中運行時,檢索數據的時間。請告訴我我能做些什麼來解決這個問題。如何處理設備中的數據庫?
您應該添加sqlite的文件(空白或預先存在的)的應用程序包,並讓應用程序知道它的存在,它在文件目錄拷貝:
BOOL success;
NSArray*dirPath;
NSString*docDir;
dirPath=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docDir=[dirPath objectAtIndex:0];
databasePath=[docDir stringByAppendingPathComponent:@"yourDB.sqlite"];
NSFileManager*filemgr=[NSFileManager defaultManager];
success=[filemgr fileExistsAtPath:databasePath];
if(success)
{
NSLog(@"Already Present");
}
NSString* bundlePath=[[NSBundle mainBundle]pathForResource:@"yourDB" ofType:@"sqlite"];
NSError*error;
success=[filemgr copyItemAtPath:bundlePath toPath:databasePath error:&error];
if(success)
{
NSLog(@"Created Successfully");
}
Iam已經寫了這一個。但從設備在回顧時數據問題將會到來。 –
聽起來你正在運行內存不足而做查詢,你可以發佈代碼嗎? – Seventoes
請在這裏發佈你的代碼的一部分... –