sqlite如何在IOS开发中应用是本文要介绍的内容,主要是来学习在IOS开发中sqlite数据库的使用方法。sqlite数据库初始化,复制到用户目录,并判断是否数据库已经存在,或者复制是否成功!
在AppDelegate.m中输入以下代码,以便复制预置数据库到指定doucment目录
-(BOol)initializeDb{ NSLog(@”initializeDB”); //looktoseeifdbisinkNownlocation(~/documents/$DATABASE_file_name) //START:code.DatabaseShopPingList.finddocumentsDirectory NSArray*searchPaths=NSSearchPathForDirectorIEsInDomains(NSdocumentDirectory,NSUserDomainMask,YES); Nsstring*documentFolderPath=[searchPathsobjectAtIndex:0]; //查看文件目录 NSLog(@”%@”,documentFolderPath); dbfilePath=[documentFolderPathstringByAppendingPathComponent:@"shopPing.db"]; //END:code.DatabaseShopPingList.finddocumentsDirectory [dbfilePathretain]; //START:code.DatabaseShopPingList.copyDatabasefileTodocuments if(![[NSfileManagerdefaultManager]fileExistsAtPath:dbfilePath]){ //dIDn’tfinddb,needtocopy Nsstring*backupDbPath=[[NSBundlemainBundle]pathForResource:@”shopPing”ofType:@”db”]; if(backupDbPath==nil){ //Couldn’tfindbackupdbtocopy,bail returnNO; }else{ BOolcopIEdBackupDb=[[NSfileManagerdefaultManager]copyItemAtPath:backupDbPathtopath:dbfilePatherror:nil]; if(!copIEdBackupDb){ //copyingbackupdbFailed,bail returnNO; } } } returnYES; //END:code.DatabaseShopPingList.copyDatabasefileTodocuments NSLog(@”bottomofinitializeDb”); } -(voID)applicationDIDFinishLaunching:(UIApplication*)application{ //copythedatabasefromthebundleifnecessary if(![selfinitializeDb]){ //Todo:alerttheuser! NSLog(@”Couldn’tinitdb”); return; } //Addthetabbarcontroller’scurrentvIEwasasubvIEwofthewindow [windowaddSubvIEw:tabbarController.vIEw]; } 总结以上是内存溢出为你收集整理的将sqlite数据库复制到用户目录全部内容,希望文章能够帮你解决将sqlite数据库复制到用户目录所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)